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().

Error on grid view paging “Failed to load viewstate.. “

I was getting “Failed to load viewstate ..” error when I was trying to load second page of grid.
I had AllowPaging=”true”, grid page size was set but even then in client’s test environment grid paging was not working at all and throwing the following error:

“Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.”.

Setting EnableViewState=false for that grid fixed this error.