本文介绍了在MVC4中,如何使用Url中的参数从控制器动作重定向到视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的MVC4登录视图中,我定义了几个部分:
In my MVC4 login view, I have several sections defined:
- 登录-/User/Login#login或--/User/Login
- 注册-/User/Login#register
- 丢失密码--/User/Login#lostpassword
页面上的JS选择了正确的表单区域来显示.
The JS on the page picks up the right form area to present.
一切都可以很好地用于登录-验证等.但是,如果注册失败,如何使用添加的#register
参数返回视图?
Everything works fine for login - validation, etc. However if the registration fails, how do I return to the view with the added #register
parameter?
-更新-我忘了提到这是来自控制器的,所有验证错误都需要传递回给它.因此,return Redirect("...")
不起作用
-- Update --I forgot to mention that this is from a controller and all validation errors need to be passed back to it. So, return Redirect("...")
doesn't work
推荐答案
以下技巧可以解决
return Redirect(Url.Action("Login", "User") + "#registerform");
URL是~/Login/User#registerform
.
这篇关于在MVC4中,如何使用Url中的参数从控制器动作重定向到视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!