【问题标题】:MVC4 Detailview from GridMvc.selectedData来自 GridMvc.selectedData 的 MVC4 Detailview
【发布时间】:2015-01-03 00:45:01
【问题描述】:

我正在尝试获取 MVCGrid 的选定行并使用局部视图在模式对话框中显示详细信息。

我正在通过 ajax 获取选定的行:

$(document).ready(function(){
 var selectedRow;
   $(document).on('click', '.grid-mvc', function () {
    pageGrids.PersonGrid.onRowSelect(function (e) {
        // $.prompt(e.row.ID);
        SendData(e.row);
       });
   });
});

“SendData”功能是:

    function SendData(i) {
    var data= i.ID;
    $.ajax({
        url: '/Home/Person',
        contentType: "application/html; charset=utf-8",
        type: "GET",
        data: { "id": daten },
        dataType: "html"
       , success: function () {
           ShowPersonDetails(data);
       }
    });
   }

ShowPersonDetails(data) 是这样的:

function ShowPersonDetails(data) {
 $(document).ready(function () {
    $('#PersonDiv').load("Person?id=" + data);
    $("#PersonDiv").prompt(
        $("#PersonDiv").html(),
        {
            title: "some title",
            buttons: { OK: 'true', Abbruch: 'false' },
            position: { width: 800, height: 600 }
    });

 });

}

控制器:

[HttpGet]
    public  ActionResult Person(int id)
    {
        var pS = new DbAccess(MvcApplication.Connection).GetUserData(id);
        var p = new Person();

        if (pS.Rows.Count < 0)
        {
            return PartialView("Person");
        }
        p.Alter = pS.Rows[0].ItemArray[0].ToString();
        p.Nachname = pS.Rows[0].ItemArray[5].ToString();
       return PartialView("Person", p);
    }

任何建议都会很好!

问候 聚丙烯

【问题讨论】:

    标签: asp.net asp.net-mvc-4 mvcgrid


    【解决方案1】:

    我做了你想做的事情,所以希望我的代码有所帮助

    在网格、表格中,我放了一个链接了解详情

        <tr>
            <td>
    @Html.ActionLink("Details", "ActionDetails", new { id = Model.LstItems[x].ID }, new { @class = "detailsLink" })
                        </td>
     </tr>
    

    javascript

        $('#detailsDialog').dialog({
            autoOpen: false,
            width: 400,
            resizable: false,
            modal: true,
            buttons: {
                "Cancel": function () {
                    $(this).dialog("close");
                }
            }
        });
    
       $(".detailsLink").button();
      $(".detailsLink").click(function () {
            linkObj = $(this);
            var dialogDiv = $('#detailsDialog');
            var viewUrl = linkObj.attr('href');
            $.get(viewUrl, function (data) {
                dialogDiv.html(data);
                //open dialog
                dialogDiv.dialog('open');
            });
            return false;
        });
    

    在视图的某处

       <div id="detailsDialog" title="Offer Details">
       </div> 
    

    控制器

        public ActionResult ActionDetails(int id)
        {
            ItemEntity model = ItemEntity .GetBy(id);
    
            return PartialView(model);
        }
    

    局部视图

          @model  YourNameSpace.Entities.ItemEntity
          @using (Ajax.BeginForm("ActionDetails", "YourController", new AjaxOptions
        {
            InsertionMode = InsertionMode.Replace,
            HttpMethod = "POST",
            OnSuccess = "updateSuccess",
            OnFailure = "showErrorMessage"
        }, new { @id = "detailForm" }))
        {
    
        //your details for your item
        }
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2014-10-23
      • 1970-01-01
      • 1970-01-01
      • 2019-02-12
      • 1970-01-01
      • 2013-08-05
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多