MVVM and ModelBinders in the ASP.NET MVC Framework

China☆狼群 提交于 2019-12-03 04:38:43

问题


I've got a series of views, each are typed to have their own ViewModel class which contains everything they need to display themselves, for example:

public class CreateResourceViewModel
{
     public Project Parent { get; set; }
     public SelectList Categories { get; set; }
     public Resource Resource { get; set; }
}

The post action method for this I'd like to use would look like this:

[AcceptVerbs (HttpVerbs.Post)]
public ActionResult Create (Resource resource)
{
   // Update code...
}

Notice that the only object I'm interested in is the Resource property of the CreateResourceViewModel, not the CreateResourceViewModel itself. Everything else is just gravy for for the user, what they're updating is the resource class...

Is this possible within the MVC Framework (even if it's v2 CTP)?

Thanks all


回答1:


Sure. Use:

 public ActionResult Create([Bind(Prefix="Resource")]Resource resource)


来源:https://stackoverflow.com/questions/1277490/mvvm-and-modelbinders-in-the-asp-net-mvc-framework

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