如何使用RedirectToAction来redirecto在页面中的位置? [英] How to use RedirectToAction to redirecto to a position in the page?
问题描述
我使用MVC4,C项目中的#和Visual Studio 2013的最终
I am using MVC4, C# and visual studio ultimate 2013 in a project.
我submiting表单后重定向用户的索引页。然而,这个网页有2个标签,我想将用户重定向,而不是第一个到第二个选项卡。
I am redirecting a user to an index page after submiting a form. However, this webpage has 2 tabs, and I want to redirect the user to the second tab, instead of the first one.
我有一个名为控制器材料
,与首页
动作,将用户的首页
查看。
I have a Controller called Material
, with an Index
action, which sends the user to the Index
View.
public ActionResult Index()
{
return View();
}
这观点是由两部分景色, _Materials
和 _Packages
。
This View is made of two partial Views, _Materials
and _Packages
.
@{
ViewBag.Title = "Index";
}
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active"><a href="#Materials" data-toggle="tab">Materials</a></li>
<li><a href="#Packages" data-toggle="tab">Packages</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="Materials">
@Html.Action("Materials", "Material")
</div>
<div class="tab-pane" id="Packages">
@Html.Action("Packages", "Package")
</div>
</div>
</div>
在应用程序的其他部分进行一个动作意甲后,我这将用户重定向到 /材料
页,第二个选项卡,但我没有知道怎么办呢!
After performing a serie of actions in another section of the application, I which to redirect the user to the /Material
page, to the second tab, but I have no idea how to do it !
目前我使用这个code,它总是重定向到第一个标签:
Currently I am using this code, which always redirects to the first tab:
return RedirectToAction("Index", "Material");
我怎样才能解决我的问题?
How can I fix my problem?
推荐答案
您无法使用类似 RedirectToAction
,因为它没有追加URL片段的任何功能。你可以做的是使用像重定向
这只是需要一个URL字符串,然后使用URL帮手还是动态生成您的行动网址:
You can't use something like RedirectToAction
because it does not have any capability of appending a URL fragment. What you can do is use something like Redirect
which just takes a URL string, and then use the URL helper to still dynamically generate the action URL for you:
return Redirect(Url.Action("Index", "Material") + "#Package");
在换句话说, Url.Action
将为您生成的主URL,并返回一个字符串。然后,您终于可以重定向之前追加片段此字符串。
In other words, Url.Action
will generate the main URL for you and return it as a string. You can then append the fragment to this string before finally redirecting.
这篇关于如何使用RedirectToAction来redirecto在页面中的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!