如果用戶在加載儀表盤頁面的動作已經FollowUpItems我將檢測,並存儲在ViewBag信息。例如,
public ActionResult Dashboard()
{
ViewBag.HasFollowupItems = UserHasFollowupItems();
return View();
}
在這個例子中,UserHasFollowupItems()
返回一個字符串,類似「真」假」。
在儀表板視圖中,添加一個空div到其中的模態數據將被加載
<div id="followup_items"></div>
然後在限定的模態,並確定相同的視圖中添加的document.ready()如果模態應加載:
$(document).ready(function()
{
// define modal
$("#followup_items").dialog({
autoOpen: false,
height: 'auto',
width: 825,
title: 'Followup Items',
position: [75, 75],
modal: true,
draggable: true,
closeOnEscape: true,
buttons: {
'Close': function()
{
$(this).dialog('close');
}
},
close: function()
{
$('.ui-widget-content').removeClass('ui-state-error');
},
});
if(@ViewBag.HasFollowupItems == 'true')
{
$('#followup_items').load("/FollowupItems/Load", function (data, txtStatus, XMLHttpRequest)
{
$('#followup_items').dialog('open');
}
});
});
在這個例子中/FollowupItems/Load
是URL到適當的控制器/動作,對於該視圖生成的數據。你是對的,這個視圖是一個局部視圖,加載到頁面上的空的followup_items div中。
因此,您可以在視圖中的任何位置使用@ViewBag對象,在這種情況下傳遞布爾值,指示是否應該加載/打開模式。我還沒有找到在外部JavaScript文件中使用ViewBag的方法,所以我通常在我的視圖中使用嵌入式腳本標記,因此我可以使用ViewBag。
您也可以以相同的方式(/FollowupItems/Load/@ViewBag.Userid
)或後續操作需要的任何其他數據添加用戶標識。
你有這個項目的jQuery? –
是的,我喜歡。我可以添加任何我想添加的內容。 – TheGeekYouNeed