這實際上是兩個問題之一。asp.net視圖語法和html幫手
第一個問題是關於以下幾點:
<div class="form-group">
@Html.LabelFor(model => model.xxx, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.xxx , new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.xxx, "", new { @class = "text-danger" })
</div>
</div>
我不明白是什麼model => model.xxx
手段,我知道它在做什麼,但我不知道如何解釋的語法。
第二個問題是,如果我有 - 例如 -
foreach (var item in Model)
我怎能取代
@Html.EditorFor(model => model.xxx , new { htmlAttributes = new { @class = "form-control" } })
與
@Html.EditorFor(item.stringProperty , new { htmlAttributes = new { @class = "form-control" } })
當我嘗試這個,它給了我錯誤,是否有一個重載的EditorFor幫助器接受這個?
謝謝!
發現了一個回答我的問題上半年這裏http://stackoverflow.com/questions/10467030/html-editorform -m-lambda-syntax-in-mvc – 2014-10-07 01:00:47
請更激動地描述你的問題。你有一個清單,你想創建...什麼?描述,然後對我和對答案會更好。 – W92 2014-10-07 01:26:41
@ W92我有一個列表,我想爲列表中的每個項目顯示一個輸入文本框,但是我希望每個文本框在其創建時都有文本,來自列表中每個項目的文本(來自項目的財產),謝謝你的幫助,我真的很感激 – 2014-10-07 01:29:45