ASP.NET MVC:回报重定向和ViewData的 [英] ASP.NET MVC: return Redirect and ViewData
问题描述
我在我的母版登录框。只要登录信息是不正确的,我稳定物价计算机[loginError]
来显示错误信息给用户。
I have a login box in my MasterPage. Whenever the login information is not correct, I valorize ViewData["loginError"]
to show the error message to the user.
登录是由于UserController的动作,使包含登录表单具有行动=/用户/登录
。
Login is an action of the UserController, so the form that contains the login has action = "/User/Login"
.
作为一个用户可以尝试从任何页面登录,在成功的情况下,我重定向他到自己的个人网页,但在错误的情况下,我希望他留下来,他试图登陆非常同一页上。我发现,这个作品:
As a user can try to log in from any page, in case of success I redirect him to his personal page, but in case of error I want him to stay on the very same page where he tried to login. I've found that this works:
return Redirect(Request.UrlReferrer.ToString());
但似乎,因为我不返回正确的视图中,ViewData的数据丢失,所以我不能显示错误消息。
but it seems that, as I'm not returning a proper view, the data on ViewData is lost, so I cannot show the error message.
如何解决这一点,类似的问题任何建议?
Any suggestion on how to solve this and similar problems?
感谢
推荐答案
您可能需要使用的TempData code>属性,这将在下一HTTP请求被持久化。
You probably want to use the TempData
property, this will be persisted across to the next HTTP request.
这篇关于ASP.NET MVC:回报重定向和ViewData的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!