Reference a control's ID created with TextBoxFor()

不羁岁月 提交于 2019-12-05 05:45:01

Since MVC4 there is a built-in way to do it - @Html.IdFor().

Here is a sample of using it:

@Html.IdFor(m => m.Filters.Occurred.From)

and the result is like

Filters_Occurred_From

I think you can do something like:

<%=Html.TextBoxFor(x => x.LastName, new { id = "LastName" })%>

Overloads of TextBoxFor

As a point of interest it appears that the Html.Textbox() code will generate an id, duplicating the control name for anything that begins with a letter (a-z). If however your 'name' begins with a number it will simply not bother.

This is a fantastic 'feature' that has caused me grief for the past hour or so.

By default your control id is your model binding value, You can also Just use firebug. select the control and get by default control id.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!