0

我正在编写一个 MVC3 项目。现在我有一个表,其中包含 Data as actionLinks 列:

<td style="color: Black; background-color: Bisque; text-align: center; width: 410px">
   @Html.ActionLink(@item.LookUp_NameString, "EditPartial", "Capitation", new { id = item.CAPITATION_RATE_ID }, new { @class = "actionLink" })
</td>

EditPartial 顾名思义是一个局部视图,我需要将其作为弹出菜单打开,以便用户可以编辑对象的详细信息,保存它,然后我们可以返回原始页面。

我已经尝试过渲染部分,但无法让它动态传递 id 值。

这是为了我的网格的编辑功能。实现这一点的最佳方法是什么?

4

1 回答 1

3

如果要在模型弹出窗口中打开 EditPartial Action 方法的结果,则需要一些模型弹出代码。

jQuery UI 是一种选择。http://jqueryui.com/demos/dialog/

1)在您的页面中包含 jQuery UI 参考,

2)将以下脚本添加到您的页面,这会将您的正常链接转换为模型弹出窗口

<script type="text/javascript">
    $(function(){
        $(".actionLink").click(function (e) {
            var url = this.href;
            var dialog = $("#dialog");
            if ($("#dialog").length == 0) {
                dialog = $('<div id="dialog" style="display:hidden"></div>').appendTo('body');
            }
            dialog.load(
                url,
                {}, // omit this param object to issue a GET request instead a POST request, otherwise you may provide post parameters within the object
                function (responseText, textStatus, XMLHttpRequest) {
                    dialog.dialog({                       
                        close: function (event, ui) {                            
                            dialog.remove();
                        },
                        modal: true,
                        width: 460, resizable: false
                    });
                }
            );           
            return false;           
        });
    });
    </script>

从您的操作结果中,您可以返回要在模型弹出窗口中显示的任何标记。大多数情况下,您将返回一个视图。如果要显示部分视图,如果是 ajax 请求,如果是正常请求则显示正常视图,您可以检查 Request.IsAjaxRequest 方法来做到这一点。

public ActionResult EditPartial(int id)
{
  CustomerViewModel objCustomer=GetCustomer(id);
  if(Request.IsAjaxRequest())
  {
     return View("Partial/Edit",objCustomer);
  }
  return View(objCustomer);

}

假设您有 2 个视图来显示您的正常页面和部分页面(用于模型弹出窗口)

我更喜欢将我的操作方法命名为,Edit而不是EditPartial,因为它同时处理请求(ajax 和普通)

于 2012-04-09T17:06:46.690 回答