views:

185

answers:

3

Due to crazyness in this project (Too long a story to get in right now), we need to keep the data in the Model of the form, but not display it on the form on successfull postback, where the form postback was succesfull -

<%= Html.TextBox("FullName", "", new { @class = "required", title = "Full Name is required" })%>

Dosent seem to do the trick - and I cant reset the model in the controller, because on post back we want a message (that appears on the same page) that pretty much says something like "Thankyou for your query regarding XYZ (which is what they entered in one of the text boxes)"

I hope that makes sense.

A: 

Try the overload of Html.TextBox that does not take a value:

Html.TextBox("FullName", 
    new { @class = "required", title = "Full Name is required" })
Robert Harvey
A: 

After post you should always redirect to avoid problems with resubmiting the form. If you want to show message, you can use TempData. Just set TempData["ThankYouMessage"] before redirecting and then, if value is set, show the message.

Here you can read about TempData in MVC 2:

http://weblogs.asp.net/jacqueseloff/archive/2009/11/17/tempdata-improvements.aspx
LukLed
+2  A: 

Sounds like a duplicate of this question. Reposting my answer here.

Sounds like a job for the PRG (Post Redirect Get) pattern because you don't want the users to refresh the page and have it submit again.

To do this I would put a message or flag in your TempData so that you can inspect that when you redirect back to the original url to then display a message to the user.

HTHs,
Charles

Charlino