0

我在使用MVC部分视图的Jquery模型弹出窗口中显示窗体。在提交时,我调用我的操作方法来验证用户输入,如果验证失败,我需要再次填充模式弹出窗口。我面对的问题是,在提交它调用子操作方法时,我能够在我的部分视图中获取ViewData.ModelState.IsValid,但无法自动显示取决于ModelState值的模式弹出窗口。我尝试在jQuery代码下面,但没有运气。模型弹出状态

管窥

@inherits Umbraco.Web.Mvc.UmbracoViewPage<WebApplicationDemo1.Models.JobAlertModel> 

<script> 
     $(function() { 
      $("#dialog-modal").dialog({ 
       autoOpen: false, 
       width: 600, 
       height: 550, 
       show: { 
        effect: "blind", 
        duration: 1000 
       }, 
       hide: { 
        effect: "dissolve", 
        duration: 1000 
       } 
      }); 

      $("#modal-opener").click(function() { 
       $("#dialog-modal").dialog("open"); 
      }); 
     }); 
</script> 



<button id="modal-opener">Job Alerts</button> 

<div id="dialog-modal" title="Basic modal dialog"> 

    @using (Html.BeginForm()) 
    { 
     <fieldset> 
      <legend>Product</legend> 
      <div class="editor-label"> 
       @Html.LabelFor(m => m.email) 
      </div> 
      <div class="editor-field"> 
       @Html.TextBoxFor(m => m.email) 
       @Html.ValidationMessageFor(model => model.email) 
      </div> 

      <div class="editor-label"> 
       @Html.LabelFor(m => m.location) 
      </div> 
      <div class="editor-field"> 
       @Html.TextBoxFor(m => m.location) 
       @Html.ValidationMessageFor(model => model.location) 
      </div> 

      <div class="editor-label"> 
       @Html.LabelFor(m => m.password) 
      </div> 
      <div class="editor-field"> 
       @Html.TextBoxFor(m => m.password) 
       @Html.ValidationMessageFor(model => model.password) 
      </div> 

      <div class="editor-label"> 
       @Html.LabelFor(m => m.search) 
      </div> 
      <div class="editor-field"> 
       @Html.TextBoxFor(m => m.search) 
       @Html.ValidationMessageFor(model => model.search) 
      </div> 

      <input type="submit" value="Create new job alert" /> 

     </fieldset> 
    } 



</div> 

@if (!ViewData.ModelState.IsValid) 
{ 
    <div>There are some errors</div> 
    <script type="text/javascript"> 
     $("#modal-opener").click(); 
    </script> 
} 

儿童行动

[ChildActionOnly] 
    [HttpPost] 
    public ActionResult JobAlert(JobAlertModel JobAlert) 
    { 
     JobAlertModel ja = new JobAlertModel(); 
     if (ModelState.IsValid) 
     { 

      ja.email = JobAlert.email; 

      return Redirect("/"); 
     } 
     else 
     { 
      return PartialView("popup", ja); 
     } 
    } 

回答

0

我弄清楚自己。如果有人想知道。

@if (!ViewData.ModelState.IsValid) 
{ 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      $("#modal-opener").click(); 
     }); 

    </script> 
}