asp.netasp.net-mvc

How to redirect to a page from a non controller in ASP.NET MVC?


I have a non-controller file called MyLib.cs where I have a method where, for a given condition, I want it to redirect to another page.

I used RedirectToAction(), but I got an error saying it dose not exist in current context.

Any ideas what I should use?


Solution

  • I think you can use Response.Redirect here. Consider this code:

    HttpContext.Current.Response.Redirect("YOUR_PAGE_Virtual_PATH"); 
    //example: http://www.mywebsite.com/home/list