下面是我寫的VIEW
<div class="row">
<div class="col-xs-1 text-dark bg-info text-right p-1">
@Html.LabelFor(model => model.Account, new { @class = "required" })
</div>
<div class="col-xs-2 text-light bg-dark p-1">
@Html.TextBoxFor(model => model.Account, new { @Value = "king" })
</div>
</div>
但是執行完後,
預設值是空的,檢視HTML也是value="",有人遇過一樣問題嗎
.net mvc htmlhelper設置value預設值好像有兩種寫法
@Html.TextBoxFor(model => model.Account, new { @Value = "king" })
@Html.TextBoxFor(model => model.Account, new { Value = "king" })
然後可以先把class拿掉看這樣子有沒有產生預設值
之後再一個一個補加回去測試看看
如果你是用.net core mvc可以嘗試透過tag helper方式
https://coolmandiary.blogspot.com/2021/08/net-core17inputtaghelper.html