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> 
}