MVC-3 ASP.NET 共享视图-重定向-Razor
我在“Views/Shared”文件夹中有一个名为 NotAuthorized 的共享视图。当用户无权查看该页面时,我想将用户重定向到此视图。
最初,该视图位于名为 Account 的文件夹中。但我将其移至共享文件夹中,因为我不再使用该帐户。我已经删除了帐户文件夹。
我使用以下代码进行重定向:
public ActionResult NotAuthorised()
{
return RedirectToAction("NotAuthorised", "Account");
}
现在我删除了“帐户”文件夹,我尝试使用
public ActionResult NotAuthorised()
{
return RedirectToAction("NotAuthorised", "Shared");
}
在最后一行中提供共享的文件夹名称,这是完全错误的。
谁能告诉我,我做错了什么?
谢谢
I have a shared view called NotAuthorised in the folder 'Views/Shared'. I want to redirect the users to this view when they are not authorised to see the page.
Initially, this view was in a folder called Account. But I moved it into the Shared folder as I am not using the Account anymore. I have deleted the Account folder.
I used the following code to redirect:
public ActionResult NotAuthorised()
{
return RedirectToAction("NotAuthorised", "Account");
}
Now that I removed the Account folder, I'm trying to use
public ActionResult NotAuthorised()
{
return RedirectToAction("NotAuthorised", "Shared");
}
I am completely wrong by giving the folder name shared in the last line.
Could anyone tell me, what I am doing wrong?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法重定向到
View
,只能重定向到Controller
的Action
。您必须为重定向指定一个控制器操作,然后您可以在其中呈现共享视图。然后从任何其他操作方法中重定向到这个新操作:
但是您可能不需要这个额外的控制器。您可以简单地渲染共享的
View
You can't redirect to a
View
, only to anAction
of aController
. You have to specify an controller action for your redirect and there you can render your shared view.and later redirect to this new action from within any other action method:
But you may not need this additional
Controller
. You could simply render the sharedView