views:

141

answers:

2

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.

+9  A: 

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.

Levi
Awesome. You are right - thanks!
thekaido
A: 

can i just ask why you would like to do that? because removing an ID seems kinda dirty to do in HTML...

Stefanvds
I disagree that it's dirty. `id` is not required, and if you don't intend to use it, then it only makes your page bigger.
Craig Stuntz