How to define ASP.NET MVC view model for parent/ch

2019-08-26 20:32发布

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 BookEdit(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

0条回答
登录 后发表回答