【发布时间】:2012-10-02 19:31:37
【问题描述】:
我在 MVC 中有以下类布局:
public class ReportModel
{
List<SomeItem> items;
string value;
string anotherValue;
}
现在我在这种类型的 MVC 中创建一个强类型视图,并制作可编辑的文本字段来编辑每个值,并使用 foreach 循环填充文本字段以编辑某些项目列表中的项目。
当我提交给 httppost 方法时,奇异值在 reportmodel 对象中恢复正常,但列表没有在对象中返回。这应该怎么做?
当我说 httppost 时,我指的是 MVC 发回的方法
[HttpPost]
public ActionResult EditReport(ReportModel report)
{
// Save the report in here after the update on the UI side
}
查看发布某项列表的代码
if (Model.items != null && Model.items.Count > 0)
{
for (int i = 0; i < Model.items.Count; i++)
{
<div class="editrow">
<div class="edititem">
<div class="editor-label">
@Html.LabelFor(m => m.items.ElementAt(i).propertyOne)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.items.ElementAt(i).propertyOne)
@Html.ValidationMessageFor(m => m.items.ElementAt(i).propertyOne)
</div>
</div>
<div class="edititem">
<div class="editor-label">
@Html.LabelFor(m => m.items.ElementAt(i).propertyTwo)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.items.ElementAt(i).propertyTwo)
@Html.ValidationMessageFor(m => m.items.ElementAt(i).propertyTwo)
</div>
</div>
<div class="edititem">
<div class="editor-label">
@Html.LabelFor(m => m.items.ElementAt(i).propertyThree)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.items.ElementAt(i).propertyThree)
@Html.ValidationMessageFor(m => m.items.ElementAt(i).propertyThree)
</div>
</div>
</div>
}
}
【问题讨论】:
-
第一:吹毛求疵:在标题中:列表,未点亮。第二:你说的httppost方法是什么?我们在这里谈论Android吗?请添加该标记以表示它。
-
你读到了吗:hanselman.com/blog/…
-
@KirillBestemyanov 这不是我想要的,因为我希望将它们返回到报告模型中,而不是作为函数的单独参数
-
@bldoron nitpicking 肯定:P haha 更新了标题并详细说明了 httppost 的含义(我认为标题中的 MVC 会暗示将帖子返回到 httppost 方法,我为错误传达道歉)
-
您需要包含显示您如何呈现列表的视图代码。没有它,我们不知道它是以什么格式发布的。
标签: asp.net-mvc http-post