2

如果调用 get 请求,ASP.NET MVC3 视图将显示验证错误。仅当像在 MVC2 中那样使用发布请求时,如何显示验证错误?

看法:

<%= Html.ValidationSummary(false, "Error") %>

控制器:

namespace Store.Controllers
{
    public class CheckoutController : MyApp.Controllers.ControllerBase
    {
        [HttpGet]
        public ActionResult Address()
        {
            return View(new AddressViewModel());
        }


        [HttpPost, ValidateAntiForgeryToken]
        public ActionResult Address(AddressViewModel model, string name) {
          if (!ModelState.IsValid)
            return View(model);

         return RedirectToAction("Payment");
         }
       }
       }
4

0 回答 0