[英]How to create child objects inside parent list through partial ASP.NET MVC 4 views
搜尋了一堆之后,我仍然停留在這個問題上。 我對Asp.Net MVC東西很陌生
假設您有那些模型類:
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
public string SthElse { get; set; }
public List BarList { get; set; }
}
public class Bar
{
public int Id { get; set; }
public string Name { get; set; }
public string SthElse { get; set; }
public Foo ParentFoo { get; set; }
}
在這里,我對Foo和Bar都有單獨的控制器,並在兩者上都使用了腳手架的Create ActionResult方法。 在Foo Create視圖上,我需要以模態形式添加一些Bar對象,並像本示例一樣顯示添加的Bar對象。
“ ASP.NET音樂商店示例”僅涵蓋您先前插入對象的情況(您無法在同一視圖上創建藝術家,風格和專輯,即IE:想象一個“添加新音樂CD”用例,您需要在能夠在創建專輯的同一視圖上創建新的藝術家和流派)。 如何使用模態視圖來實現?
您能給我指個教程還是涵蓋這種情況(在同一視圖中創建一個新的Foo和Bar子級)?
先感謝您。
這很容易。
模型
public class FooBar {
public Foo Foo {get;set;}
public Bar Bar {get;set:}
}
調節器
public class FooBarController : Controller
{
public ActionResult Index() {};
public ActionResult Edit(FooBar model)
{
}
}
視圖:
@model FooBar
@using(Html.BeginForm) {
@EditorFor(x => x.Foo)
@EditorFor(x => x.Bar)
<input type="submit"/>
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.