MVC4验证摘要未显示

 mobiledu2502876347 发布于 2023-02-12 17:39

创建了一个模型并使用必填字段并用于创建如下表单:

模型:

public class formModel {
    [Required]
    public string name {get;set;}
    [Required]
    public string Add1 {get;set;}
    etc....
}

视图:

@model myProj.Models.formModel

@using (BeginForm("Action", "Controller", FormMethod.Post))
{
    @Html.TextBoxFor(f => f.name)
    @Html.TextBoxFor(f => f.Add1)
    etc...

    @Html.ValidationSummary()
    
}

控制器:

[HttpPost]
public ActionResult Action(formModel f)
{
    if (ModelState.IsValid)
    {
        // Do Stuff here
        return RedirectToAction("Result");
    }
    return RedirectToAction("Form", new { id = "showForm" });
 }

问题是如果模型有效,则显示验证摘要.在许多其他形式上使用了相同的方法,并且很好.

有任何想法吗?

1 个回答
  • 当模型无效时,请勿使用

    return RedirectToAction("Form");
    

    return View(f); // or return View("ViewName", f);
    

    2023-02-12 17:40 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有