您需要使用input
控件的name
属性来匹配您的模型属性名称。
例如,在您目前的情况下,如果您想要将TextBoxFor()
替换为input
控件,请按如下方式操作:
文本框:
@Html.TextBoxFor(m=> m.Name)
<input name="Name" type="Text" value="@Model.Name"/>
下拉列表:
@Html.DropDownListFor(m=>m.SomeProperty,ItemsList)
<select name="SomePropertyType">
<option value="someValue">Some Text</option>
</select>
对于下拉列表的情况,我们需要采取同样的方式。
@Html.BeginForm():
@using(Html.BeginFor("ActionName","ControllerName",FormMethod.Post))
{
}
在 HTML 中,如果要创建表单,您需要使用 form 标签:
<form action="@Url.Action("ActionName","ControllerName")" method="post">
</form>
更新:
@Html.TextBoxFor(m=>m.SomeProperty")
在HTML中:
<input id="SomeProperty" name="SomeProperty" type="text" value="@Model.SomeProperty" />
@Html.TextAreaFor("SomeName", "", 10, 50, null)
在HTML中为:
<textarea cols="50" id="SomeName" name="SomeName" rows="10">
密码用于:
@Html.PasswordFor(m=>m.SomeProperty)
以 HTML 格式为:
<input id="SomeProperty" name="SomeProperty" type="password" />
请参考Scottgu的这篇文章以及这篇CodeProject文章