문제

나는 그런 텍스트 상자의 ID와 이름을 수동으로 정의하고 싶습니다 :

<%: Html.TextBoxFor(model => model.Name, new { @id = "txt1", @name = "txt1" })%>
.

그러나 ID 만 변경되며 이름 속성이 아닌 이유는 무엇입니까?

<input id="txt1" name="Name" type="text" value="">
.

고맙습니다!

도움이 되었습니까?

해결책

You can't use the strongly typed lambda version for this, you'd need to use the older version

Html.TextBox("txt1",new {@id = "txt1"})

다른 팁

This is ok:

<%: Html.TextBoxFor(model => model.Name, new { Name = "txt1" })%> 

Do you write "Name" instead of "name"?

Output:

<input  name="txt1" type="text" value=""> 

Actually you can... just use Name with first letter capitalized instead of name:

@Html.TextBoxFor(model => model.Property, new { Name = "myName" })

If you still need to use TextBoxFor(), you can change the name of the property on your model, which should be easy if you're using dedicated ViewModels as is recommended. However I admit it's a recommendation I don't always follow myself.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top