Search code examples
asp.net-mvcrazoreditorfor

How to add id to textbox with Html.EditorFor statement?


I try to add id to textbox but get error. I should use Html.EditorFor() statement.Please advice.

My code:

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

Solution

  • I believe you should add the id property to the html attributes.

    @Html.EditorFor(m => m.Historicals.HistoricalName, 
        new { htmlAttributes = new { @class = "form-control", id = "Historical_place_name" } });