How to define ASP.NET MVC view model for parent/child relationship and its view (*.cshtml)
I have a domain model below:
public class Book
{
public List<Author> Authors = new List<Author>();
}
public class Author
{
public Book Book { get; set; }
public string Name { get; set; }
}
I want to define an edit view for a book, below is the action methods:
public ActionResult BookEd开发者_运维问答it(int id)
{
BookModel model = GetBook(id);
return View(model);
}
[HttpPost]
public ActionResult BookEdit(BookModel bookModel)
{
BookModel model = new BookModel();
return View(model);
}
Two questions:
Question 1: how to best define the view models for both Book and Author.
Question 2: How to define the view (*.cshtml), particularly on Book property of Author, which should be hidden. The other part has been resovled on Expose collections in view
Thanks
精彩评论