tags:

views:

100

answers:

1

Trying to run the reportviewer with passing the parameter but receive error:

Validation of viewstate MAC failed error (ASP.NET MVC)

Have tried the following but no luck:

  1. added the machine key (http://aspnetresources.com/tools/machineKey) to the system.web tag in web.config

  2. set enableEventValidation="false" to the pages tag in web.config.

any helps?

+1  A: 

We had the same problem not a long ago and after a lot of searching the following code has solved the problem:

protected override object LoadPageStateFromPersistenceMedium()
{
    string viewState = Request.Form["__VSTATE"];
    LosFormatter formatter = new LosFormatter();
    return formatter.Deserialize(viewState);
}

protected override void SavePageStateToPersistenceMedium(object viewState)
{
    LosFormatter formatter = new LosFormatter();
    System.IO.StringWriter writer = new System.IO.StringWriter();
    formatter.Serialize(writer, viewState);
    string viewStateString = writer.ToString();
    ClientScript.RegisterHiddenField("__VSTATE", viewStateString);
}

We have put it in the view in script tags, which is not very beautiful, but it works...

Further details see: http://stackoverflow.com/questions/121579 and http://www.codeproject.com/KB/viewstate/ViewStateCompression.aspx

apolka
yes.. not so beautiful.. but you know what?!.. who cares!.. it solved the problem anyway.. :) you are a legend mate!.. thanks again.
I am happy that it helped. :)
apolka