Can ASP.NET MVC html helpers render an element without an ID attribute?

跟風遠走 提交于 2019-12-06 18:43:14

问题


Assume I want to generate an element similar to this in ASP.NET MVC 2:

<%= Html.TextBoxFor(p => p.FooBar)%>

Is there an overload or way I can get ASP.NET MVC 2 to only generate a name attribute and not an ID attribute?

I can have it generate a blank id with <%= Html.TextBoxFor(p => p.FooBar, new { id = "" })%>, but I would like to generate the element with no ID at all, and without overriding the asp.net mvc framework.


回答1:


The behavior of the HTML helpers was changed as of MVC 2 RC1 so that passing new { id = "" } suppresses id entirely rather than outputting an empty id attribute.



来源:https://stackoverflow.com/questions/2398599/can-asp-net-mvc-html-helpers-render-an-element-without-an-id-attribute

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