我正在使用Ajax请求来呈现部分视图,但是当模型有一些错误时,它应该呈现完整的View,我的代码有什么问题,或者应该更改什么
[Authorize(Roles = AuthStrings.AdminRole)]
[ValidateAntiForgeryToken]
[HttpPost]
public ActionResult Create(Module module)
{
try
{
if (ModelState.IsValid)
{
new ModuleService().Insert(module);
return PartialView("_ModuleResult", module.DataUrl);
}
return View(module);
}
catch (ModelExistsException e)
{
ModelState.AddModelError("Name", e.Message);
return Redirect
}
catch (Exception e)
{
return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest);
}
}
我正在使用Ajax Helpers
@using (Ajax.BeginForm("Create", new AjaxOptions { HttpMethod = "Post", UpdateTargetId = "folderPath"}))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
..Here is form fields
</div>
}
<div id="folderPath">
</div>
<div>
@Html.ActionLink("Back to List", "Index")
</div>