MVC Quick Tips

1. How to redirect to another action from with in an Action
RedirectToAction("ToActionName", new { id = 99 });

id will be name of parameter for which value is being passed.

ActionLink passing parameter as QueryString

In MVC Razor ActionLinke, it is a common requirement to pass parameter as a query string. It creates URL like below:


and of course basically it is <a href="/CodeTest/EditClass/1">Edit</a>

ActionLink provide different overloads, using one of them such links can be generated:

@Html.ActionLink("Home", "Edit", new {id=1})

Instead of hard coded strign a model property can also be used:

@Html.ActionLink("Home", "Edit", new {id=Model.Id})


If you are using T4MVC templates is a little different from above examples, then you will code as per below example:

and using model:

For passing multiple parameters use AddRouteValues().

#mvc, #razor