tags:

views:

96

answers:

2

I have a home page with a search box and a button on it.

I click the search button and i go to a results page.

the results page also has a search button and when i click it i get the error Validation of viewstate MAC failed

<% using( Html.BeginForm("Result", "Search" )){ %>
<%= Html.TextBox("SearchText", Model.SearchText)%>
<input value="" type="submit"/>

Both pages contain the above piece of code.

If i use the same master page for both pages i don't get the error. if they use different master pages i get the error.

i have turned off enableEventValidation and viewStateEncryptionMode and i still get the error.

UPDATE

When I press the button in both views, the views ActionResult is called, data is collected but when i say return View(myFormViewModel) I get the error.

So all's good as far as the controller is concerned I think.

+1  A: 

Do your pages or master pages contain any declarative controls? Generally these are elements that have a runat="server" somewhere in the markup.

You can also see this error if you're using the built-in anti-XSRF helpers. If you have an action decorated with [ValidateAntiForgeryToken], be sure that any form posting to it contains a call to Html.AntiForgeryToken().

Levi
None of the above. I don't use runat="server" with my mvc projects. In fact, the master pages don't contain any controls at all.
griegs
I just tried <%= Html.AntiForgeryToken() %> coupled with [ValidateAntiForgeryToken] and no go either.
griegs
Going to give you the answer because in a way you were right. Should have read my code more closely.
griegs
A: 

Ah, my fault.

I completely missed the <form tag on the second master which meant there was a form within a form on the second master.

So infuriating!

Sorry everyone.

griegs