Tui*_*izi 6 html asp.net asp.net-mvc asp.net-mvc-2 html.textboxfor
我想手动为文本框定义id和名称:
<%: Html.TextBoxFor(model => model.Name, new { @id = "txt1", @name = "txt1" })%>
Run Code Online (Sandbox Code Playgroud)
但只有id被更改,而不是name属性,为什么?
<input id="txt1" name="Name" type="text" value="">
Run Code Online (Sandbox Code Playgroud)
谢谢!
小智 17
还行吧:
<%: Html.TextBoxFor(model => model.Name, new { Name = "txt1" })%>
Run Code Online (Sandbox Code Playgroud)
你写" 名字 "而不是"名字"吗?
输出:
<input name="txt1" type="text" value="">
Run Code Online (Sandbox Code Playgroud)
Len*_*rri 10
实际上你可以......只使用Name
首字母大写而不是name
:
@Html.TextBoxFor(model => model.Property, new { Name = "myName" })
Run Code Online (Sandbox Code Playgroud)
您不能使用强类型lambda版本,您需要使用旧版本
Html.TextBox("txt1",new {@id = "txt1"})
Run Code Online (Sandbox Code Playgroud)