ASP MVC HTTP GET行动对象作为参数

问题描述:

在我的控制器我的行动:

In my controller I got action:

[HttpGet]
public ActionResult CreateAdmin(object routeValues = null)
{
    //some code
    return View();
}

和HTTP POST:

And http post:

[HttpPost]
 public ActionResult CreateAdmin(
    string email, 
    string nameF, 
    string nameL, 
    string nameM)
 {
        if (email == "" || nameF == "" || nameL == "" || nameM == "")
        {
            return RedirectToAction("CreateAdmin", new
            {
                error = true,
                email = email,
                nameF = nameF,
                nameL = nameL,
                nameM = nameM,
            });
  }

HTTP变量routeValues​​获得行动总是空空的。如何正确地传递对象作为参数 [HTTP GET]操作

variable routeValues in http get Action is always empty. How correctly pass object as parameter to [http get] Action?

您不能传递一个对象来获取,而不是试图传递个人价值是这样的:

You cannot pass an object to GET, instead try passing individual values like this:

[HttpGet]
public ActionResult CreateAdmin(int value1, string value2, string value3)
{
    //some code
    var obj = new MyObject {property1 = value1; propety2 = value2; property3 = value3};
    return View();
}

您可以再从你的应用程序的任何地方传递值,如:

You can then pass values from anywhere of your app like:

http://someurl.com/CreateAdmin?valu1=1&value2="hello"&value3="world"