Reputation: 1579
How comethis does not work? I am trying to add a new HTML attribute to the EditorFor. @Html.EditorFor(model => model.Name, new { data_autocomplete="/index/QuickSearch"})
Upvotes: 0
Views: 842
Reputation: 5381
Unfortunately the EditorFor helper doesn't include the html attributes parameter that the other helpers do. This is because you can make custom editor templates (see http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html for an outdated MVC2 example), so it doesn't make sense to have html attributes, as there could be many HTML tags in the template.
Your best bet is to either write your own helper extension method OR, if your editor is always, for example, a TextBox, use TextBoxFor().
Upvotes: 1
Reputation: 10743
with jQuery you could attach the attribute after the DOM has finished loading:
document.ready(function() {
$('#Name').attr('data-autocomplete', '/index/QuickSearch');
}
Upvotes: 0