Yuriy Mayorov Yuriy Mayorov - 1 month ago 10
ASP.NET (C#) Question

asp mvc http get action with object as parameter

In my controller I got action:

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


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


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

Answer

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"