Dot-Net
如何在 Razor 語法中設置 @Html.TextBoxFor 的值?
我使用 Razor 創建了一個文本框,並嘗試
value如下設置。@Html.TextBoxFor(model => model.Destination, new { id = "txtPlace", value= "3" })我試過
value附加@@Html.TextBoxFor(model=> model.Destination, new { id = "txtPlace", @value= "3" })即使它呈現
input空的html標籤value<input id="txtPlace" name="Destination" type="text" value class="ui-input-text ui-body-c ui-corner-all ui-shadow-inset ui-mini" >做錯了什麼?
問題是您使用的是小寫的 v。
您需要將其設置為 Value ,它應該可以解決您的問題:
@Html.TextBoxFor(model => model.Destination, new { id = "txtPlace", Value= "3" })