我从RandomNumbers列表与收集Submittet对象丢失,新的集合数据
我得到这个简单的类
public class Test
{
public string Name { get; set; }
public List<int> RandomNumbers { get; set; }
public Test()
{
RandomNumbers = new List<int>(){0,0,0,0,0};
}
}
在我的控制,我创建获得新的数据有问题中的两个ActionResults一个为获取一个用于邮政
public ActionResult Test()
{
var test = new Test();
return View(test);
}
[HttpPost]
public ActionResult Test(Test test)
{
return View();
}
,最后查看
@model Test
@{
ViewBag.Title = "Test";
Layout = null;
}
<h2>Test</h2>
@using (Html.BeginForm())
{
@Html.LabelFor(model => model.Name)
@Html.EditorFor(model => model.Name)
<ul>@foreach (var t in Model.RandomNumbers)
{
<li>
@Html.LabelFor(model => t)
@Html.EditorFor(model => t)
</li>
}
</ul>
<input type="submit" value="Save"/>
}
网页看起来是这样的。 现在当我点击保存按钮时,[HttpPost]
测试被调用,但是包含的测试对象只包含新名称,没有包含随机数列表中的更改。我做错了什么?
不知道如何使用它,因为我” m不直接绑定到集合,而是绑定到具有集合的对象。 – gulbaek