MVVM并在ASP.NET MVC框架ModelBinders [英] MVVM and ModelBinders in the ASP.NET MVC Framework

查看:142
本文介绍了MVVM并在ASP.NET MVC框架ModelBinders的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了一系列的意见,每个被键入拥有包含他们需要展示自己的一切,例如自己的ViewModel类:

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; }
}

为了这个,我想使用POST操作方法是这样的:

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...
}

请注意,我唯一感兴趣的对象是CreateResourceViewModel,而不是CreateResourceViewModel本身的资源属性。其他的一切只是肉汁对用户来说,他们要更新的是资源类...

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...

这是可能的MVC框架(即使它V2 CTP)?

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

感谢所有

推荐答案

当然。用途:

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

这篇关于MVVM并在ASP.NET MVC框架ModelBinders的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆