3
我嘗試通過使用jquery單擊按鈕來顯示一個彈出窗口,該按鈕位於與元素對應的一行的每一端。在對話框中呈現partila視圖(彈出)
檢視:
<input type="button" id="DetailButton" value="Details" onclick="GetDetails(this);"/>
腳本:
function GetDetails(sender) {
var IdElement = $($(sender).parent().parent()).find('input').val();
$.ajax({
type: 'GET',
url: "/ControllerName/ActionName",
data: encodeURI("IdElement=" + IdElement) ,
success: function (view) {
//How to render a view in popup ?
}
});
}
對話框 「DialogDetails」 是一個局部視圖:
<div id="PopUpDetails" >
<table>
<thead>
<tr>
<th colspan="1">Element</th>
</tr>
</thead>
<tbody>
<%
foreach (var Item in Model.List)
{ %>
<tr>
<td>
<%:Html.DisplayFor(model => Item.IdElement) %>
</td>
</tr>
<%} %>
</tbody>
</table>
</div>
控制器:
public ActionResult ActionName(int IdElement)
{
ElementViewModel model = new ElementViewModel();
return View("DialogDetails", model);
}
我已經試過這個,不起作用 – fatys
有人有另一個想法嗎?我在部分視圖中返回部分視圖,但不在對話框中 – fatys
試試這個,在您的部分視圖中,爲document.ready添加一個偵聽器:$(document).ready(function(){//然後調用$('#dialogDiv ').dialog();在那裏,也許視圖沒有完成加載,或者嘗試在設置視圖之後調用它之前使用超時,這對我來說確實很有用。 –