这实际上是两个问题之一。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