0

一個彈出我有一個包含與它們的ID和標題作業列表面板。 它只是一個簡單的視圖和一個簡單的控制器去配合它。創建partialview數據asp.net mvc5

public ActionResult Index() 
    { 
     ViewBag.menuItem = "DashBoard"; 
     return View(db.jobs.ToList()); 

    } 

列表中的項目:

<li class="list-group-item"> @item.ID @item.Title</li> 

我創建了一個細節控制器來顯示工作的局部視圖:

[HttpGet] 
    public ActionResult Details (int jobID) 
    { 

     var details = db.details.Find(jobID); 
     return PartialView(details); 
    } 

,只需sandard視圖去用它。使用腳手架。

我如何添加一個動作鏈接到該列表時,與工作細節匹配其ID點擊,將顯示一個彈出框。

回答

0

通過彈出框,你的意思是莫代爾?如果是的話:

更改您的清單,這部分

<li class="list-group-item"><a data-id="@item.ID" href="#">@item.Title</a></li> 

我要你使用jQuery和Bootstrap承擔?如果沒有,我會提供下面的鏈接,並檢查出來。

$('.list-group-item a').click(function(){ 
    //gets the id for the selected list item 
    var itemId = $(this).data("id"); 

    //performs an ajax call to the controller to get the details based on the id selected 
    $.ajax({ 
    url : 'your controller url', 
    type : 'POST', 
    data : { 
     'jobID' : itemId 
    }, 
    dataType:'json', 
    success : function(data) {    
     //append the results to your modal's body. 
     //$("modal selector").modal('show'); 
    }, 
    error : function(error) 
    { 
     //do something with the error 
    } 
    }); 
}); 

鏈接Bootstrap ModalsjQuery