部分视图为何不加载

时间:2013-03-15 09:35:27

标签: asp.net-mvc-3-areas

我有这样的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 LookupTypeName=@0)", "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 LookupTypeName=@0)", "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>

1 个答案:

答案 0 :(得分:0)

我不喜欢&#39;请看这里插件的初始化..

我直接看到了:

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

但是在哪里初始化带有选项的对话框? 我认为您应该在成功响应中初始化对话框,而不是直接调用函数&#39; open&#39;。

查看doc jquery ui dialog

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

我希望能帮到你