【发布时间】:2014-12-01 08:15:51
【问题描述】:
这实际上是两个问题合二为一。
第一个问题是关于以下内容:
<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 帮助器接受这个?
谢谢!
【问题讨论】:
-
在这里找到了我问题前半部分的答案stackoverflow.com/questions/10467030/…
-
请更准确地描述您的问题。你有一个列表,你想创建......什么?描述,那么对我和答案都会更好。
-
@W92 我有一个列表,我想为列表中的每个项目显示一个输入文本框,但我希望每个文本框在创建时都有文本,其中每个项目的文本清单(来自物品的属性),顺便感谢您的帮助,非常感谢
-
看看我的答案(编辑后)
-
谢谢你的更新,给我一分钟试试
标签: c# asp.net asp.net-mvc html-helper