GridMvc.selectedData中的MVC4详细信息视图



我正在尝试获取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(数据)是这样的:

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);
    }

任何建议都很好!

问候PP

我做了一些像你试图做的事情,所以希望我的代码能帮助

在表格的网格中,我放了一个链接来查看的详细信息

    <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
    }

希望这能帮助你

相关内容

最新更新