【问题标题】:When clicking "open in a new window" on an Ajax.ActionLink in MVC partial view to reload the whole page在 MVC 局部视图中单击 Ajax.ActionLink 上的“在新窗口中打开”以重新加载整个页面
【发布时间】:2014-05-19 12:55:37
【问题描述】:

您好,在我的 homeController 中,我有一个返回强类型局部视图的操作

 public virtual ActionResult ImportShow(String id, String menuID, string articlegroupID)
        {

            GroupMenu p_GroupMenu = new GroupMenu();
            p_GroupMenu.LanguageName = p_country;


             p_GroupMenu.MenuHistory = p_GetMenuHistory.ToList();
            p_GroupMenu.MenuLeft = p_GetMenuLeft.ToList();

            return PartialView("ImportShow",p_GroupMenu);
        }

在我的 partialView ImportShow 我只渲染两个局部视图

@model  MvcBeaWeb.GroupMenu

    <div id="importPartUpdate">
        <div class="heading-history">  


                @Html.Partial("MenuHistoryShow")

        </div>
        <aside id="asideIndex">
            <div class="leftMenu">
                <div id="sidebar">

                     @Html.Partial("MenuLeftShow")



                </div>
            </div>

在我的 MenuLefShow PartialView 中,我有一个 Ajax.ActionLink 再次指向 ImportShow 操作方法,它将更新 importPartUpdate div

@model MvcBeaWeb.GroupMenu

<div class="divLeftShowMenu">
    <ul>
        @{
            if (Model != null)
            {
                foreach (MvcBeaDAL.WebServiceBeaMenu item in Model.MenuLeft)
                {

                  <li id="@item.ID">

                    @Ajax.ActionLink(item.SpecialWord, "ImportShow", "Home", new { id = Model.LanguageName, menuID = item.ID, articlegroupID=item.ArticlegroupID }, new AjaxOptions
                    {
                       UpdateTargetId = "importPartUpdate",
                       HttpMethod = "GET",
                       InsertionMode = InsertionMode.Replace
                    })

                  </li> 
                }
            } 
        }
    </ul>
</div> 

--所以问题是 - 例如,当用户单击“在新窗口中打开”时 - 这意味着在新窗口中将只有这个“ImportPartUpdate”div。所以有什么我可以说的方法 - 如果用户右键单击“在新窗口中打开” - 转到索引操作并重新加载整个页面。

【问题讨论】:

    标签: jquery ajax asp.net-mvc


    【解决方案1】:

    可以在控制器动作方法中查看Request.IsAjaxRequest()

    if (!Request.IsAjaxRequest())
    {
         return //go to action for none ajax request
    } 
    

    【讨论】:

    • 是的,我已经添加了您的代码,现在我收到错误消息“不允许子操作执行重定向操作。”
    • 实现 !Request.IsAjaxRequest() 后你的代码是什么样的?
    猜你喜欢
    • 2011-05-17
    • 2017-04-11
    • 2014-07-18
    • 1970-01-01
    • 2011-09-14
    • 2015-01-11
    • 2011-02-03
    • 1970-01-01
    相关资源
    最近更新 更多