Asp.net mvc 3 服务器端错误的ValidationSummary不工作

Asp.net mvc 3 服务器端错误的ValidationSummary不工作,asp.net-mvc-3,asp.net-mvc-4,asp.net-mvc-validation,Asp.net Mvc 3,Asp.net Mvc 4,Asp.net Mvc Validation,客户端验证和验证摘要在我的项目(MVC4+Razor+Unobtrusive JS)中运行良好,但服务器端错误不会显示在我的视图中,如果存在任何客户端错误,它不会从视图中删除(它会从ModelState中删除)。我试过Chrome14和IE9 服务器端错误作为ModelState.addmodeleror(string.Empty,ModelState.AllErrors())添加到模型中并显示为@Html.ValidationSummary(false) 编辑 Simple form subm

客户端验证和验证摘要在我的项目(MVC4+Razor+Unobtrusive JS)中运行良好,但服务器端错误不会显示在我的视图中,如果存在任何客户端错误,它不会从视图中删除(它会从ModelState中删除)。我试过Chrome14和IE9

服务器端错误作为
ModelState.addmodeleror(string.Empty,ModelState.AllErrors())添加到模型中
并显示为
@Html.ValidationSummary(false)

编辑

Simple form submit工作正常,它显示从服务器返回的多条错误消息并更新错误消息,但是,基于ajax的form submit不工作基于ajax的form submit返回的错误消息根本不显示

下面是如何提出请求的示例演示

    @*... View contents related to Master Model  ...*@
    @using (Ajax.BeginForm("ActionToAddRecord", new AjaxOptions()))
    {
        @Html.Action("ActionToAddRecord")
        <input type="submit" value="Add Record"/>
    }
    @*... View contents related to Master Model  ...*@
编辑


我在VS2010的模板化MVC应用程序(基于对话框的登录表单)中看到了类似的功能。错误消息以Json的形式返回,然后使用JS来显示它们,IMO,似乎MS使基于Ajax的请求变得非常简单和简洁(
Ajax.BeginForm
),但缺少错误处理部分。现在我不愿意使用JS来处理这个问题,可能有更好的方法来自动处理这种类型的错误。

解决了,只需一个小错误

主视图

@*Master View Contents*@
        @using (Ajax.BeginForm("AddPaymentCurrency", new AjaxOptions { UpdateTargetId = "paymentCurrency" }))
        {
            <div id="paymentCurrency"> 
                @{Html.RenderPartial("PaymentCurrency", Model.PaymentCurrencyNew);}
            </div>
        }
@*Model Editors*@
@Html.ValidationSummary(false)
<input type="submit" value="Add Payment Currency"/>

<div id="paymentCurrencyList" style="width:inherit; height:auto; overflow:auto;"> 
    @Html.Action("PaymentCurrencyList")
</div>
小错误

[HttpPost]
public ActionResult AddPaymentCurrency(PaymentCurrency model)
{
    if (!ModelState.IsValid)
    {
        ModelState.AddModelError(string.Empty, ModelState.AllErrors());
        return View("PaymentCurrency", model);
    }
    //Add login
    return View("PaymentCurrency", model);
}

public ActionResult PaymentCurrencyList()
{
    //var list = getList
    return View(list);
}
添加无效支付货币时,将显示ValidationSummary,并突出显示字段,并对其显示星号。添加有效货币后,ValidationSummary和星号将不再显示在无效支付货币上,只突出显示字段

请帮助我将其修复,我不希望更改当前结构,否则我将开始出现大错误

[HttpPost]
public ActionResult AddPaymentCurrency(PaymentCurrency model)
{
    if (!ModelState.IsValid)
    {
        ModelState.AddModelError(string.Empty, ModelState.AllErrors());
        return View("PaymentCurrency", model);
    }
    //Add login
    return View("PaymentCurrency", model);
}

public ActionResult PaymentCurrencyList()
{
    //var list = getList
    return View(list);
}