Web1) Create a form manually using the normal html helpers and construct the model in the controller 2) Rename all the fields in the model to fit the format Neither of these are exciting to me so I am hoping for an alternative but am afraid that the id is what is used when binding the form to a model. asp.net-mvc-4 razor Share Improve this question WebMay 4, 2014 · Upgrade to MVC 5.1 and you can use HTML attributes in EditorFor: @Html.EditorFor (m => m.variable, new { htmlAttributes = new { placeholder = "Your Placeholder Text" } }) http://www.asp.net/mvc/overview/releases/mvc51-release-notes Share Improve this answer Follow edited Aug 26, 2015 at 17:52 Josh M. 26.1k 24 116 …
Set disable attribute based on a condition for Html.TextBoxFor
WebMar 20, 2015 · @if ( (bool)ViewBag.Readonly) { @Html.EditorFor (model => model.Quantity, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } }) } else { @Html.EditorFor (model => model.Quantity, new { htmlAttributes = new { @class = "form-control" } }) } Share Improve this answer Follow edited Mar 19, … WebFeb 19, 2016 · Here’s an example of how I used it to add an ARIA “aria=required” attribute: @Html.EditorFor (model => model.City, new { htmlAttributes = new { … roman burger meat
Html5 data-* with asp.net mvc TextboxFor html attributes
WebFeb 10, 2024 · Solution 2. As of ASP.NET MVC 5.1, adding a class to an EditorFor is possible (the original question specified ASP.NET MVC 3, and the accepted answer is still the best with that considered). @Html .EditorFor (x=> x.MyProperty, new { htmlAttributes = new { @class = "MyCssClass" } }) WebIf you don't want to use EditorFor, you always can use TextBox helper or simple html. But that is not the question! – chandmk Feb 24, 2011 at 0:11 @Aaron as of latest MVC, you can specify additional html attributes with EditorFor by passing it as: new { htmlAttributes: { @class = "yourclass" } } – JoeBrockhaus Dec 19, 2014 at 17:28 Add a comment 18 WebJul 16, 2012 · 3 Answers. I think I found a little nicer solution to it. EditorFor takes in additionalViewData as a parameter. If you give it a parameter named "htmlAttributes" with the attributes, then we can do interesting things with it: @Html.EditorFor (model => model.EmailAddress, new { htmlAttributes = new { @class = "span4", maxlength = 128, … roman burning