我有一个ASP.NET MVC表单,当提交时可以返回ActionResult
,如果数据有错误,或者一切正常,它会重定向到返回FileResult
的不同操作。ASP.NET MVC如何在操作返回FileResult时重置表单?
我已经创建了一些样本来提供我正在做的事情的想法。这是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" />
<% } %>
和控制器代码:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult MyPostSample(string YourName)
{
if (string.IsNullOrEmpty(YourName))
{
ModelState.AddModelError("YourName", "You must specify a name");
}
if (ModelState.IsValid)
{
// get the file
RedirectToAction("GetFile");
}
else
{
// return this actions View with errors
return View();
}
}
public FileResult GetFile(string YourName)
{
// return file here
}
的原因ActionResult
是填充ModelState中的错误,以便用户可以纠正并再试一次。
这一切工作正常,除了我希望表单被重置或清除,如果服务器返回一个文件。目前用户获得一个文件对话框,但表单保留了提交的值。如何在成功提交后重置表单?
请参阅http://stackoverflow.com/questions/2345756/ http://stackoverflow.com/questions/2297670/ http://stackoverflow.com/questions/707569/ – 2010-02-28 22:02:45