Search code examples
c#asp.net-mvcroutevalues

Convert a string into routeValues for call RedirectToAction


Is possible to convert a string into routeValues?

Per example:

return RedirectToAction("Index", "Home", new { id = 1});

to

return RedirectToAction("Index", "Home", "id = 1");

I am needing it because I want to save the routeValues in database.

I already read this: convert string into (object) routeValues C# but the guy doesn't know if that is the more supported way.


Solution

  • RedirectToAction also takes a RouteValueDictionary which might be usable in your case. You'd have to construct it a little differently.

    var routeVals = new RouteValueDictionary(){"id", "1"};
    return RedirectToAction("Index", "Home", routeVals);