Convert a string into routeValues for call RedirectToAction

963 Views Asked by At

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.

1

There are 1 best solutions below

0
JamieD77 On BEST ANSWER

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