Sirius
Sirius

Reputation: 13

Redirecting in asp.net 5

I am still learning to work with asp.net and I am trying to redirect to an Edit action in a controller from another controller, but I can’t find out how to make it work. this is what I have

return RedirectToAction("Edit", "Worker"); 

or

return RedirectToAction("Edit", "Worker", 25); 

I need it to be something like this: http://localhost:xxxxx/Worker/Edit/25

Upvotes: 1

Views: 924

Answers (2)

Tushar Gupta
Tushar Gupta

Reputation: 15933

You can pass the route value parameters as Route value Object using the new Keyword...as

return RedirectToAction("Edit", "Worker", new { id = 25}); 

And if you want to add multiple values you can go like adding the values separated by a comma ,

return RedirectToAction("Edit", "Worker", new { id = 25,name ="tushar"}); 

Or you can create a RouteValueDictionary , add the items and send the object of it at once as

RouteValueDictionary _routValueDict = new RouteValueDictionary();
_routValueDict.Add("param1", param1);
_routValueDict.Add("param2", param2); 

No pass the object like :

return RedirectToAction("Edit", "Worker", _routValueDict );

Upvotes: 1

Tasos K.
Tasos K.

Reputation: 8087

You can do the following

return RedirectToAction("Edit", "Worker", new { id = 25}); 

Upvotes: 1

Related Questions