Djeroen
Djeroen

Reputation: 571

MVC5 redirect to internal url

Is there a way to link to an internal Url in mvc5?
I get the url like so: Source = Request.RawUrl
this returns: "/Clients/AddNote"
but it can also have parameters: "/Clients/AddNote/12?items=10"

This is the code that i have so far:

string[] url = Source.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
string Controller = url[0];
string Action = url[1];
try{                    
    string id = url[2];
    return RedirectToAction(Action, Controller, new { id = id});
   }
catch{}

return RedirectToAction(Action, Controller);

this works good when there is only an ID ad parameter but this code does not handle the named parameters like: ?items=10

is there a way that i can just say: return RedirectToAction("/Clients/AddNote/12?items=10");?

Upvotes: 1

Views: 1420

Answers (1)

Khazratbek
Khazratbek

Reputation: 1656

Have you tried to use: Request.AbsoluteUri ?

Upvotes: 1

Related Questions