How to define ASP.NET MVC view model for parent/child relationship and its view (*.cshtml)

霸气de小男生 提交于 2019-12-12 02:04:25

问题


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

来源:https://stackoverflow.com/questions/6843500/how-to-define-asp-net-mvc-view-model-for-parent-child-relationship-and-its-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!