Firoz Jafri
Firoz Jafri

Reputation: 168

ASP.NET MVC : redirect to action using URI

How can we redirect to a particular action using System.Uri

public ActionResult Edit(MyModel model)
{
    Uri url = System.Web.HttpContext.Current.Request.UrlReferrer; 

    if (condition)
    {
        return View(url);
    }
    return View(model);
}

i want to redirect the page to url

Please help

Upvotes: 2

Views: 2655

Answers (1)

jgauffin
jgauffin

Reputation: 101150

There is a Redirect() method which takes an url.

The trick is to convert it to a string first as the Redirect() method do not take an Uri object:

public ActionResult Edit(MyModel )
{
    Uri url = System.Web.HttpContext.Current.Request.UrlReferrer; 

    if (condition)
    {
        return Redirect(url.ToString());
    }
    return View(model);
}

MSDN documentation

Upvotes: 5

Related Questions