Dan
Dan

Reputation: 1575

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.

Upvotes: 0

Views: 973

Answers (1)

JamieD77
JamieD77

Reputation: 13949

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

Upvotes: 1

Related Questions