2016-03-07 46 views
0

我尝试将id添加到文本框但出现错误。我应该使用Html.EditorFor()声明。请咨询。如何使用Html.EditorFor语句将id添加到文本框?

我的代码:

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

它需要是'@ Html.EditorFor(M => m.Historicals.HistoricalName,新的{htmlAttributes =新{@class = “形式控制”,ID = “Historical_place_name”}})' –

+0

但是使用'EditorFor()'方法已经添加的'id'有什么问题? (这是'id =“Historicals_HistoricalName”') –

+0

谢谢。它解决了 – programmer138200

回答

1

我相信你应该id属性添加到HTML属性。

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

请删除“,null” – programmer138200

相关问题