I have an ASP.NET MVC form that, when submitted, can return either ActionResultif there was a data error, or if everything is in order, it redirects to another action that returns FileResult.
I created a little example to give an idea of what I am doing. This is html:
<%
using (Html.BeginForm())
%>
<%= Html.ValidationSummary(
"Edit was unsuccessful. Please correct the errors and try again.") %>
<%= Html.TextBox("YourName", Model.YourName)%>
<%= Html.ValidationMessage("YourName", "*") %>
<input type="submit" />
<% } %>
and controller code:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult MyPostSample(string YourName)
{
if (string.IsNullOrEmpty(YourName))
{
ModelState.AddModelError("YourName", "You must specify a name");
}
if (ModelState.IsValid)
{
RedirectToAction("GetFile");
}
else
{
return View();
}
}
public FileResult GetFile(string YourName)
{
}
The reason for this ActionResultis to fill out ModelState errors so that the user can fix and try again.
All this works fine, except that I would like the form to be reset or cleared if the file is returned by the server. Currently, the user receives the File dialog, but the form retains the submitted values. What can I do to reset the form after successful submission?