Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 849
bkaid Avatar asked Mar 08 '10 00:03

bkaid


People also ask

What is the difference between HTML helpers and tag helpers?

Tag Helpers are attached to HTML elements inside your Razor views and can help you write markup that is both cleaner and easier to read than the traditional HTML Helpers. HTML Helpers, on the other hand, are invoked as methods that are mixed with HTML inside your Razor views.

What is the role of HTML helper in ASP.NET MVC?

In MVC, HTML Helper can be considered as a method that returns you a string. This string can describe the specific type of detail of your requirement. Example: We can utilize the HTML Helpers to perform standard HTML tags, for example HTML<input>, and any <img> tags.

How many types of HTML helpers are there in MVC?

There are three types of built-in HTML helpers offered by ASP.NET.

What does HTML helper class generate?

The HtmlHelper class generates HTML elements. For example, @Html. ActionLink("Create New", "Create") would generate anchor tag <a href="/Student/Create">Create New</a> . There are many extension methods for HtmlHelper class, which creates different HTML controls.


1 Answers

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.

like image 135
Levi Avatar answered Sep 20 '22 15:09

Levi