来自GridMvc.selectedData的MVC4 Detailview

时间:2014-11-06 13:26:12

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

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

我通过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是:

    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

1 个答案:

答案 0 :(得分:0)

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

在网格,表格中,我提供了一个详细信息链接

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

希望这能帮到你