2013-03-15 134 views
0

我的jQuery這樣,我試圖加載的局部視圖,但它沒有工作,那麼顯示對話框,沒有任何控制爲什麼局部視圖不加載

mvcJqGrid.demo.edit = function(id) { 

      var grid = $('#Products'); 
      var myCellData = grid.jqGrid('getCell', id, 'ProductId'); 
      GetProduct(myCellData); 

      return false; 


     }; 
function GetProduct(id) 
     { 

      $("#dialog-form").load("@Url.Action("EditProduct","Admin")", 
       function (response, status, xhr) { 
        $("#dialog-form").dialog('open'); 
       }); 



     } ; 

我的動作是:

[HttpPost] 
    public ActionResult EditProduct(string productId) 
{ 
     int id = 0; 
     Product product = null; 
     bool result = int.TryParse(productId,out id); 
     ProductModel productModel=new ProductModel(); 
     Session["ProductModule"] = productModel.GetProduct(id); 
     return PartialView("Product_Partial", Session["ProductModule"] as ProductModel); 
    //return RedirectToAction("Product", "Admin"); 

    } 

我的部分觀點是:

@using (Html.BeginForm("Product","Admin",method:FormMethod.Post)) 
{ 

<fieldset> 
    <legend>Product Information</legend> 
    <div class="editor-label"> 
     @Html.LabelFor(m => m.ProductTitle) 
    </div> 
    <div class="editor-field"> 
     @Html.TextBoxFor(m => m.ProductTitle) 
    </div> 
    <div class="editor-label"> 
     @Html.LabelFor(m => m.ProductTypeId) 
    </div> 
    <div> 
     <select name="ProductType"> 
      <option value="null">Select ProductType</option> 
      @foreach (var row in new Database("MyConnectionString").Query<LookUp>("select * from Lookup where LookupTypeId=(select LookupTypeId from LookupType where [email protected])", "ProductType")) 
      { 
       <option value="@row.LookupId">@row.LookupName</option> 
      } 
     </select> 
    </div> 
    <div class="editor-label"> 
     @Html.LabelFor(m => m.BrandId) 
    </div> 
    <div > 
     <select name="Brand"> 
      <option value="null">Select Brand</option> 
      @foreach (var row in new Database("MyConnectionString").Query<LookUp>("select * from Lookup where LookupTypeId=(select LookupTypeId from LookupType where [email protected])", "Brand")) 
      { 
       <option value="@row.LookupId">@row.LookupName</option> 
      } 
     </select> 
    </div> 
    <div class="editor-label"> 
     @Html.LabelFor(m => m.BasePrice) 
    </div> 
    <div class="editor-field"> 
     @Html.TextBoxFor(m => m.BasePrice) 
    </div> 
    <div class="editor-label"> 
     @Html.LabelFor(m => m.ProductSpecification) 
    </div> 
    <div class="editor-field"> 
     @Html.TextBoxFor(m => m.ProductSpecification) 
    </div> 
    <div class="editor-label"> 
     @Html.LabelFor(m => m.ProductSummary) 
    </div> 
    <div class="editor-field"> 
     @Html.TextBoxFor(m => m.ProductSummary) 
    </div> 
    <div class="editor-label"> 
     @Html.LabelFor(m => m.IsOutOfStock) 
    </div> 
    <div class="ui-icon-check"> 
     @Html.CheckBoxFor(m => m.IsOutOfStock) 
    </div> 


    <table> 
     <tr> 
      <td> 
       <input type="submit" value="Add" onclick="@Url.Action("Product", "Admin")" /> 
      </td> 
      <td> 
       <button type="submit" id="btnDelete" name="Command" value="Update" onclick="@Url.Action("Product", "Admin")" >Update</button> 
      </td> 
      <td> 
       <button type="submit" id="btnSearch" name="Command" value="Delete" onclick="@Url.Action("Product", "Admin")">Delete</button> 
      </td> 
     </tr> 

    </table> 
</fieldset> 

} 

我的看法頁:

<div id="dialog-form" title="Add New Product"> 

</div> 
+0

我安裝更新,因此不能檢查,但...你要加載的動作說HttpPost它上面。嘗試將其改爲HttpGet。並將返回類型設置爲PartialViewResult而不是ActionResult。 – VictorySaber 2014-02-11 09:01:49

回答

0

我不看此插件的初始化..

我直接看到:

$("#dialog-form").dialog('open'); 

但如果你初始化與選項的對話框? 我認爲你應該在你的成功響應中初始化對話框,而不是直接調用'open'函數。

doc jquery ui dialog

$("#dialog-form").load("@Url.Action("EditProduct","Admin")", 
      function (response, status, xhr) { 
       $("#dialog-form").dialog(); 
      }); 

我希望會幫助你

相關問題