我正在尝试在我的控制器上实现 restful 约定,但不确定如何处理失败的模型验证以将其从 Create 操作发送回“New”视图。
public class MyController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult New()
{
return View();
}
[HttpPost]
public ActionResult Create(MyModel model)
{
if(!ModelState.IsValid)
{
// Want to return view "new" but with existing model
}
// Process my model
return RedirectToAction("Index");
}
}