更改MVC控制器中的URL导航 [英] Change the URL navigation in MVC controller
问题描述
当我在我的主页面完成我的工作时,我必须去巢1.
我尝试从下一页控制器那样做`loginController`
当我在主控制器中时,我使用以下功能:
While I Finishing my job in my main page I have to go to the nest one.
I try to do that from the next page controller lets say `loginController`
While I'm in the main controller I use the following function for this purpose:
Public Sub FlagBtn_Click(ByVal myFlag As String) As ActionResult
Attributes.envProp._LanguageFlag = myFlag
Attributes.mvcLogin.Index()
End Sub
程序进入接下来`loginController`并在那里执行函数:
The program goes to the next `loginController` and executes the function there:
<Route("Login")>
Function Index() As ActionResult
Return View()
End Function
通常需要更改` url`也可以根据`route file`
Which normally has to change the `url` as well according to the `route file`
routes.MapRoute(
name:="Default",
url:="{controller}/{action}/{id}",
defaults:=New With {.controller = "main", .action = "Index", .id = UrlParameter.Optional}
)
但这不会发生。而不是那个`url`导航仍然在`Default`路线上,当然下一页无法显示。
这里的问题是如何更改`url`导航,根据我选择去的页面。
我尝试了什么:
没有比我已经做过的更多
But that doesn't happen. Instead of that the `url` navigation remains on the `Default` route and of course the next page can't be display.
The question here is how to change the `url` navigation, according to page I choose to go.
What I have tried:
Nothing more than I have already done
推荐答案
使用 RedirectToAction [ ^ ]将浏览器重定向到另一个动作。
Use RedirectToAction[^] to redirect the browser to another action.
Public Sub FlagBtn_Click(ByVal myFlag As String) As ActionResult
Attributes.envProp._LanguageFlag = myFlag
Return RedirectToAction("Index", "login")
End Sub
注意:该方法的第一行看起来很可疑。您是否尝试在请求之间的字段中存储值?那不行。您需要使用会话状态或 TempData
集合来保存数据。
NB: The first line of that method looks suspicious. Are you trying to store values in a field between requests? That won't work. You'd need to use session state, or the TempData
collection, to persist the data.
这篇关于更改MVC控制器中的URL导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!