更改ajax UpdatetargetID取决于模型状态验证MVC

更改ajax UpdatetargetID取决于模型状态验证MVC,ajax,model-view-controller,Ajax,Model View Controller,假设我有一个简单的ajax开始表单: @using (Ajax.BeginForm("DodajTresc", "Administracja", new AjaxOptions { Confirm = "Czy jesteś pewien że chcesz dodać treść ?", InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace, UpdateTargetId = "podgladDodanejTresc", Loadi

假设我有一个简单的ajax开始表单:

@using (Ajax.BeginForm("DodajTresc", "Administracja", new AjaxOptions { Confirm = "Czy jesteś pewien że chcesz dodać treść ?", InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace, UpdateTargetId = "podgladDodanejTresc", LoadingElementId = "spinWiadomosci" }))
{
    some code[...]
}
是否可以在模型状态验证后更改UpdatetargetID?。对于exmaple:

if(ModelState.IsValid)
{
    UpdatetargetID="div1";
}
else
{
    UpdatetargetID="div2";
}

是否有一个选项可以实现这一点?

您可以使用OneRor,如果State not valid抛出异常并在OneRor js函数中执行任何需要的操作OK,我将尝试使用它。谢谢