Redirection with parameters

0

I have the following method:

public ActionResult exemplo()

That returns:

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

The index of the page receives:

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

but the last action parameter is reset! 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?

    
asked by anonymous 02.01.2018 / 14:47

1 answer

1

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

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

Ideally, you should change the parameter name 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 to use an at sign before the parameter name (not tested):

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