2016-03-07 78 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