Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i set the html id attribute in razor

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

like image 212
Mustafa Sattar Avatar asked Nov 03 '25 13:11

Mustafa Sattar


1 Answers

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" }})
like image 82
Tobias Avatar answered Nov 05 '25 10:11

Tobias



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!