2014-11-06 33 views
0

我試圖讓MVCGrid的選擇行和使用partialview在模態對話框顯示的細節。MVC4的DetailView從GridMvc.selectedData

我通過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

回答

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 
    } 

希望這有助於你