How can i set the html id attribute in razor

asp.net-mvc, asp.net-mvc-5, razor

Solution

Just add the id property to the html-attributes. That will override the default id generated by the editorfor-helper-methode.

Look at this post: How can I set id using Html.EditorFor with MVC3

 @Html.EditorFor(model => model.News_Date, new { htmlAttributes = new { @class = "form-control", id = "my_custom_id" }})

Problem

I want to configure datepicker in my MVC 5 form. I have included all the reference libraries like Jquery, datepicker etc. Following is the line from MVC razor view, which is created by Visual Studio in a result for MVC 5 scaffolding. ``` @Html.EditorFor(model => model.News_Date, new { htmlAttributes = new { @class = "form-control" }}) ``` any help in this regard

Original source

Related problems