Navid Kianfar
Navid Kianfar

Reputation: 171

Losing Route data in RedirectToAction

hi i have a weird problem and here we go:

i am redirecting using this command :

return RedirectToAction("ViewMessage", "Account", new {id = model.MessageId});

but in ViewMessage action when i try to get id, its null ?!?!?!?!??

string strMessageId = RouteData.Values["id"] as string;

i have done this code in lots of places and it works fine but i dont know what is going on here.... :(

i know i can use TempData but i dont want to :)

Upvotes: 1

Views: 2099

Answers (3)

trycatchfinally
trycatchfinally

Reputation: 43

Check your routing configuration. If your action parameter name is "id" then your routing url pattern should be {controller}/{action}/{id}.

Upvotes: 0

Arjun Shetty
Arjun Shetty

Reputation: 1585

Actually the way you did worked for me still Try This


return RedirectToAction("ViewMessage",new RouteValueDictionary(new {controller="Account",action="ViewMessage", id = model.MessageId }));

Upvotes: 1

Avinash Rao
Avinash Rao

Reputation: 1

Try accessing the route value using the View Context

ViewContext.RequestContext.RouteData.Values("id")

Upvotes: 0

Related Questions