在HTTP GET请求MVC3模型绑定? [英] MVC3 Model binding in HTTP GET request?

查看:129
本文介绍了在HTTP GET请求MVC3模型绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有定制,我可以做这样的事情在MVC 3?

Without customization, can I do something like this in MVC 3?

    [HttpGet]
    public ViewResult MyAction(ViewModel model)
    {
        // Do stuff
        return View("ViewName", model);
    }

我这样做的原因是不同的页面之间的数据传递作为工作流的一部分。 (即当用户fnishes我们所需要的步骤1中,通过表单数据步骤2 ...)

The reason I am doing this is to pass data between different pages as part of a work flow. (I.e. when user fnishes what's needed in step 1, pass the form data to step 2...)

推荐答案

这将工作,只要你有相同的参数名称作为你的模型类的属性名

It will work as long as you have the same parameter Name as of the Property name of your Model class

假设你的类是这样的。

public class ViewModel
{
  public string Name { set;get;}
  public string Loc{ set;get;}
}

您可以这样做一个GET请求

You can do a Get request like this

MyAction?Name=jon&Loc=America

这篇关于在HTTP GET请求MVC3模型绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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