Redirection with parameters

Asked

Viewed 271 times

0

I have the following method:

public ActionResult exemplo()

Returning:

int act = (int)TasksTypeEnum.CARGA;
return RedirectToAction("Index", new { q = study.Id, msg = 1, action = act });

The page index receives:

public ActionResult Index(int q, int msg = 0, int action = 0)

but the last action parameter comes zeroed ! and the url ends up like this:

Ciclos?q=3886&msg=1

the value of this: int Act = (int)TasksTypeEnum.CARGA; is = 1

public enum TasksTypeEnum
    {
        CARGA = 1,
        STATUS = 2,
        SINISTRO = 3, 
        EMAIL = 4,
        CONTATOTELEFONICO = 5      
    }

Why are you ignoring this last parameter ?

1 answer

1


The action parameter you are using is already reserved for the name of the action to be called, as it was defined in the route registration:

config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{action}/{id}",
    defaults: new
    {
        action=RouteParameter.Optional
    }
);

Ideally you would change the name of the parameter as in the example below:

int act = (int)TasksTypeEnum.CARGA;
return RedirectToAction("Index", new { q = study.Id, msg = 1, _action = act });

public ActionResult Index(int q, int msg = 0, int _action = 0)

If this is not possible, try using an arroba before the parameter name (I have not tested):

return RedirectToAction("Index", new { q = study.Id, msg = 1, @action = act  });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.