2

我有一个带有链接的表的视图。单击链接时,JQuery 通过 ajax 加载 PartialViewResult。问题是当用户单击局部视图中显示的结果中的链接并转到另一个页面然后单击后退按钮时,在原始页面上呈现的局部视图的内容不再出现在页面上。如果用户单击浏览器后退按钮,如何显示渲染的局部视图?

查询...

 <script type="text/javascript">

 function getGroup(id) {
     var link = "Search/GroupDetails/" + id;
     $('#Group').load(link);
     $('#Group').show();
 }

这被加载到 DIV

 <div id="Group">
 </div>

控制器局部视图

        public PartialViewResult GroupDetails(string id)
    {
        SearchIndexViewModel newSIVM = new SearchIndexViewModel();
        id = Help.FormatID(id);
        CCRUser ccrUser = _CCRUser.GetUser();
        newSIVM.CCRUser = ccrUser;

        if (!string.IsNullOrEmpty(id))
        {
            newSIVM.Selected_Group = _Groups.GetSingleGroup(id, cUser);
            newSIVM.Group_Owner = _Groups.GetGroupOwner(id, cUser);
            newSIVM.Group_Members = _Groups.GetGroupMembers(id, cUser);        
            HttpContext.Session["SELECTEDGROUPNAME"] = id;

        }

        return PartialView("_GroupDetails", newSIVM);
    }
4

1 回答 1

0

你可以在你的脚本中有一个 document.ready 函数。每次加载原始视图时都会触发它。(我检查过,即使你按下后退按钮它也会被触发)

$(document).ready(function() {
    // Check the session value from the server by sending a ajax request. 
    // You can use the success function of the ajax request to call the get group function
    // If a SELECTEDGROUPNAME exists
    getGroup(1);

});
于 2013-09-11T16:38:49.240 回答