2014-09-13 157 views
0

我創建了一個使用腳手架選項創建operation.I只是試圖加載到jquery ui Dialog.I能夠加載部分視圖(MVC4)加載我失去了MVC 4爲我生成的所有驗證。AJAX加載scafolded MVC 4局部視圖

是否有可能將部分視圖(腳手架)加載到jQuery對話框?

這裏是我已經使用了彈出

$(function() { 
    $("#CreateDialog").dialog({ 
     autoOpen: false, 
     buttons: { 
      "Create": function() { 
       $(this).dialog("close"); 
      } 
     }, 
     dialogClass: "no-title", 
     hide: { 
      effect: "scale", 
      easing: "easeInBack" 
     }, 
     show: { 
      effect: "scale", 
      easing: "easeOutBack" 
     } 
    }); 
}); 

function openModalPopUp() { 

$.ajax({ 
    type: 'GET', 
    url: '/Expense/CreatePartial', 
    cache: false, 
    success: function (result) { 
     $('#CreateDialog').html(result); 
    } 
}); 

$("#CreateDialog").dialog("open"); 

}

和我的模型(樣本)代碼:

@model EFMvcWebRole.Models.ExpenseEntity 

@using (Html.BeginForm()) { 
    @Html.AntiForgeryToken() 
    @Html.ValidationSummary(true) 

    <fieldset> 
     <legend>ExpenseEntity</legend> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.ECValue) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.ECValue) 
      @Html.ValidationMessageFor(model => model.ECValue) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Category) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Category) 
      @Html.ValidationMessageFor(model => model.Category) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.TotalSalary) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.TotalSalary) 
      @Html.ValidationMessageFor(model => model.TotalSalary) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.Remaining) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.Remaining) 
      @Html.ValidationMessageFor(model => model.Remaining) 
     </div> 

    </fieldset> 
+0

你提交使用提交按鈕或任何按鈕的onclick事件用ajax發送數據的形式。 請向我展示您的提交代碼。 – 2014-09-15 05:04:55

回答

2

只包含JS文件,即Jquery Unobtrusive js文件在您部分視圖也工作得很好,有時候這個問題出現在asp.net mvc的部分視圖中(因爲表單是動態添加到DOM中的)。

只是包含這個js文件在你的局部視圖也:

<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script> 

------------------或嘗試這部分景觀---- ----------------------

$.validator.unobtrusive.parse($("form")); 
+0

@ Hsakarp ..我想以上答案將解決您的問題,如果需要更多的幫助,然後評論..謝謝.. – 2014-09-14 12:39:06

+0

是啊,我正在測試,將盡快發佈。謝謝 – codebot 2014-09-15 05:27:51

+0

@Hsakarp ...工作..? – 2014-09-15 07:03:04