Asp.net mvc 手柄';在新窗口中打开';当单击ajax.ActionLink时,该链接指向返回部分视图的操作
您好,我有一个操作,它从数据库中获取一些数据并返回一个局部视图 在部分视图中有ajax.actionLinks,单击该链接时执行相同的ImportShow操作,但这次使用新数据;正如您在cshtml中看到的,然后仅使用新数据更新 我试图解决的问题是,如果用户在新窗口中单击“在新窗口中打开”或“在新选项卡中打开”,您将看到仅加载了此部分视图。在这种情况下,我想不出一种方法来重定向并重新加载整个页面。(链接指向返回局部视图的操作方法之后) 作为 MvcBeaWeb.GroupMenu型号Asp.net mvc 手柄';在新窗口中打开';当单击ajax.ActionLink时,该链接指向返回部分视图的操作,asp.net-mvc,Asp.net Mvc,您好,我有一个操作,它从数据库中获取一些数据并返回一个局部视图 在部分视图中有ajax.actionLinks,单击该链接时执行相同的ImportShow操作,但这次使用新数据;正如您在cshtml中看到的,然后仅使用新数据更新 我试图解决的问题是,如果用户在新窗口中单击“在新窗口中打开”或“在新选项卡中打开”,您将看到仅加载了此部分视图。在这种情况下,我想不出一种方法来重定向并重新加载整个页面。(链接指向返回局部视图的操作方法之后) 作为 MvcBeaWeb.GroupMenu型号 @{
@{
如果(型号!=null)
{
foreach(Model.MenuLeft中的MvcBeaDAL.WebServiceBeaMenu项)
{
-
@ActionLink(@item.SpecialWord,“ImportShow”,new{id=Model.LanguageName,menuID=@item.id},new-AjaxOptions{UpdateTargetId=“importPartUpdate”,HttpMethod=“GET”,InsertionMode=InsertionMode.Replace})
}
}
}
以前有一些帖子有这个问题,您可以查看并发布。基本上发生的是:当您单击“ajax”链接时,这是一个ajax调用,因此部分视图被渲染,一切都按预期工作。但是,当您右键单击以在浏览器中的新选项卡或新窗口查看页面时,这不是AJAX调用,但您返回的是部分视图,新选项卡或窗口仍将返回部分视图。这就是为什么你只能看到局部视图
为了说明我的意思:
下面是代码片段
public class HomeController : Controller
{
List<Person> people = new List<Person>()
{
new Person { Name = "Larry", Age = 10},
new Person { Name = "Jessie", Age = 11},
new Person { Name = "Ben", Age = 12},
new Person { Name = "Victor", Age = 13},
new Person { Name = "Tom", Age = 14},
new Person { Name = "Suresh", Age = 15},
new Person { Name = "Jim", Age = 16},
};
public ActionResult Index()
{
return View();
}
public ActionResult GetPerson()
{
Random r = new Random();
int i = r.Next(0, people.Count);
if (Request.IsAjaxRequest())
{
return PartialView(people[i]); //return partial if it's a ajax call
}
else
{
return View(people[i]); // return view if it's NOT a ajax call
}
}
}
公共类HomeController:控制器
{
列出人员=新列表()
{
新人{Name=“Larry”,年龄=10},
新人{Name=“Jessie”,年龄=11},
新人{Name=“Ben”,年龄=12},
新人{Name=“Victor”,年龄=13},
新人{Name=“Tom”,年龄=14},
新人{Name=“Suresh”,年龄=15},
新人{Name=“Jim”,年龄=16},
};
公共行动结果索引()
{
返回视图();
}
公共行动结果GetPerson()
{
随机r=新随机();
int i=r.Next(0,人数);
if(Request.IsAjaxRequest())
{
return PartialView(people[i]);//如果是ajax调用,则返回partial
}
其他的
{
return视图(people[i]);//如果不是ajax调用,则返回视图
}
}
}
索引视图:
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@Ajax.ActionLink("replace", "GetPerson", new AjaxOptions { UpdateTargetId = "replaceMe", HttpMethod = "Get", InsertionMode = InsertionMode.Replace})
<div id = "replaceMe"></div>
@{
ViewBag.Title=“Index”;
}
指数
@ActionLink(“replace”,“GetPerson”,新的AjaxOptions{UpdateTargetId=“replaceMe”,HttpMethod=“Get”,InsertionMode=InsertionMode.replace})
局部视图:
@model MvcApplication1.Controllers.Person
<div>
Name : @Model.Name <br />
Age : @Model.Age
</div>
@model mvcapapplication1.Controllers.Person
名称:@Model.Name
年龄:@Model.Age
以前有一些帖子有这个问题,您可以查看并发布。基本上发生的是:当您单击“ajax”链接时,这是一个ajax调用,因此部分视图被渲染,一切都按预期工作。但是,当您右键单击以在浏览器中的新选项卡或新窗口查看页面时,这不是AJAX调用,但您返回的是部分视图,新选项卡或窗口仍将返回部分视图。这就是为什么你只能看到局部视图
为了说明我的意思:
下面是代码片段
public class HomeController : Controller
{
List<Person> people = new List<Person>()
{
new Person { Name = "Larry", Age = 10},
new Person { Name = "Jessie", Age = 11},
new Person { Name = "Ben", Age = 12},
new Person { Name = "Victor", Age = 13},
new Person { Name = "Tom", Age = 14},
new Person { Name = "Suresh", Age = 15},
new Person { Name = "Jim", Age = 16},
};
public ActionResult Index()
{
return View();
}
public ActionResult GetPerson()
{
Random r = new Random();
int i = r.Next(0, people.Count);
if (Request.IsAjaxRequest())
{
return PartialView(people[i]); //return partial if it's a ajax call
}
else
{
return View(people[i]); // return view if it's NOT a ajax call
}
}
}
公共类HomeController:控制器
{
列出人员=新列表()
{
新人{Name=“Larry”,年龄=10},
新人{Name=“Jessie”,年龄=11},
新人{Name=“Ben”,年龄=12},
新人{Name=“Victor”,年龄=13},
新人{Name=“Tom”,年龄=14},
新人{Name=“Suresh”,年龄=15},
新人{Name=“Jim”,年龄=16},
};
公共行动结果索引()
{
返回视图();
}
公共行动结果GetPerson()
{
随机r=新随机();
int i=r.Next(0,人数);
if(Request.IsAjaxRequest())
{
return PartialView(people[i]);//如果是ajax调用,则返回partial
}
其他的
{
return视图(people[i]);//如果不是ajax调用,则返回视图
}
}
}
索引视图:
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@Ajax.ActionLink("replace", "GetPerson", new AjaxOptions { UpdateTargetId = "replaceMe", HttpMethod = "Get", InsertionMode = InsertionMode.Replace})
<div id = "replaceMe"></div>
@{
ViewBag.Title=“Index”;
}
指数
@ActionLink(“replace”,“GetPerson”,新的AjaxOptions{UpdateTargetId=“replaceMe”,HttpMethod=“Get”,InsertionMode=InsertionMode.replace})
局部视图:
@model MvcApplication1.Controllers.Person
<div>
Name : @Model.Name <br />
Age : @Model.Age
</div>
@model mvcapapplication1.Controllers.Person
名称:@Model.Name
年龄:@Model.Age
以前有一些帖子有这个问题,您可以查看并发布。基本上发生的是:当您单击“ajax”链接时,这是一个ajax调用,因此部分视图被渲染,一切都按预期工作。但是,当您右键单击以在浏览器中的新选项卡或新窗口查看页面时,这不是AJAX调用,但您返回的是部分视图,新选项卡或窗口仍将返回部分视图。这就是为什么你只能看到局部视图
为了说明我的意思:
下面是代码片段
public class HomeController : Controller
{
List<Person> people = new List<Person>()
{
new Person { Name = "Larry", Age = 10},
new Person { Name = "Jessie", Age = 11},
new Person { Name = "Ben", Age = 12},
new Person { Name = "Victor", Age = 13},
new Person { Name = "Tom", Age = 14},
new Person { Name = "Suresh", Age = 15},
new Person { Name = "Jim", Age = 16},
};
public ActionResult Index()
{
return View();
}
public ActionResult GetPerson()
{
Random r = new Random();
int i = r.Next(0, people.Count);
if (Request.IsAjaxRequest())
{
return PartialView(people[i]); //return partial if it's a ajax call
}
else
{
return View(people[i]); // return view if it's NOT a ajax call
}
}
}
公共类HomeController:控制器
{
列出人员=新列表()
{
新人{Name=“Larry”,年龄=10},
新人{Name=“Jessie”,年龄=11},
新人{Name=“Ben”