Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redirect to aspx page in a controller action

Tags:

asp.net-mvc

is it possible to redirect to an aspx page in an (asp.net-mvc3 )controller action? What should be the return type of the action (ActionResult?) and which redirect method should be called (RedirectToAction?).

BR,

like image 722
hazimdikenli Avatar asked Oct 19 '12 15:10

hazimdikenli


People also ask

How do I redirect a controller to another page?

Use this: return RedirectToAction("LogIn", "Account", new { area = "" }); This will redirect to the LogIn action in the Account controller in the "global" area.

How do I redirect a page to another page in MVC 5?

You can use any of the following methods to return a RedirectResult: Redirect – Http Status Code 302 Found (temporarily moved to the URL provided in the location header) RedirectPermanent – Http Status Code 301 Moved Permanently. RedirectPermanentPreserveMethod – Http Status Code 308 Permanent Redirect.

How do I redirect to another action?

To redirect the user to another action method from the controller action method, we can use RedirectToAction method. Above action method will simply redirect the user to Create action method.

Can you use ASPX pages in MVC?

If you add a plain ASPX page to an ASP.NET MVC project, well, it just works like a charm without any changes to the configuration. If you invoke the ASPX page, the ASPX page is processed with viewstate and postbacks.


2 Answers

You can redirect to anywhere from MVC action and you have to use RedirectResult for that. RedirectResult is a type of ActionResult.

For ex.

public RedirectResult RedirectToAspx()
{
  return Redirect("/pages/index.aspx");
}
like image 134
VJAI Avatar answered Sep 30 '22 07:09

VJAI


Yes, just like razor.

View:

test.aspx

Controller:

    public ActionResult test()
    {
        ViewBag.Message = "test。";

        return View();
    }
like image 26
ChunHao Tang Avatar answered Sep 30 '22 07:09

ChunHao Tang