Reputation: 1533
After Googling a bunch, I'm still stuck on this problem. I'm pretty new on Asp.Net MVC things
Say you have those model classes:
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; }
}
Here I have individual controllers to Foo and Bar with a scaffolded Create ActionResult method on both. On the Foo Create view, I need to add some Bar objects with a modal form and show added Bar objects like on this example.
The ASP.NET Music Store Example only covers the case where you have previously inserted objects (you couldn't create Artist, Genre and Album at the same view, I.E.: Imagine an "Add new Music CD" use-case where you need to be able to create a new Artist, a new Genre at the same view where you create an Album). How do I could accomplish that using modal views?
Could you point me a tutorial or else that covers this scenario (Create a new Foo and Bar children at the same view)?
Thank you in advance.
Upvotes: 0
Views: 1927
Reputation: 93444
This is easy.
Model
public class FooBar {
public Foo Foo {get;set;}
public Bar Bar {get;set:}
}
Controller
public class FooBarController : Controller
{
public ActionResult Index() {};
public ActionResult Edit(FooBar model)
{
}
}
View:
@model FooBar
@using(Html.BeginForm) {
@EditorFor(x => x.Foo)
@EditorFor(x => x.Bar)
<input type="submit"/>
}
Upvotes: 1