我開始使用ASP.NET MVC4和我有一些小的麻煩:) 我有一個視圖模型,看起來像這樣:ASP.NET MVC 4 - 泛型列表 - 視圖 - Ajax.ActionLink
public class Adulte{
public string Name {get;set;}
public List<Child> Children {get;set;}
}
public class Child{
public string Name {get;set;}
public int Age {get;set;}
}
我想動態添加/刪除我的視圖中的子項。
@Ajax.ActionLink("Add Child",
"AddChild",
new { ???= ??? },
new AjaxOptions
{
InsertionMode = InsertionMode.InsertAfter,
HttpMethod = "POST"
}
)
.....
@using (Html.BeginForm())
{
<div id="parent">
<p>
@Html.Label("Name")
@Html.TextBoxFor(x => x.Name)
<p>
</div>
<div id="children">
</div>
<input type="submit" value="Save" />
}
但我不知道發送到ActionLink的哪些參數,我和型號以及Model.Children沒有成功測試。
這可以做到嗎?
任何幫助?
你傳遞給你的觀點是什麼模型? – Longball27
我試圖通過Adulte和從控制器。 的[AcceptVerbs(HttpVerbs.Post)] 公共的ActionResult的AddChild(Adulte AdulteItem) { 如果(AdulteItem.Children == NULL)AdulteItem.Children =新列表(); \t AdulteItem.Children.Add(new Child()); return PartialView(「ChildView」,AdulteItem); } –
Stan92