The name RedirectToAction does not exist in the current context
i have a Log on in APS MVC 2.0 and if not logged on, i want to redirect the user to that page.
i found the way to do it is usin the RedirectAction (found several times on google, even on stack Overflow)
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentP开发者_C百科laceHolderID="MainContent" runat="server">
<h2><%: ViewData["Message"] %></h2>
<p>
<% if (Request.IsAuthenticated) { %>
Go to this page <%: Html.ActionLink("Manage Payment Run", "ManagePaymentRun")%>
<%} else { %>
<% return RedirectToAction("LogOn", "Account"); %>
<% } %>
</p>
</asp:Content>
Now, the problem is that i get "The name RedirectToAction does not exist in the current context". I was wondering if anyone here knows why this happens, since my googling skill didnt even get close to finding anyone with a similar problem.
Thanks for your time.
Unless I'm wrong, RedirectToAction
is method used within a controller. It's part of the Controller class and thus cannot be used from a view.
I think you may need to read through this blog post for more info in helping you.
精彩评论