-3

So I have a something like this in my cshmtl:

<div>
    <a href="/cars"></a>
</div>
<div>
    <a href="/bikes"></a>
</div>

So it goes to cars controller and hits the function below:

[HttpGet]
[Route("cars")]
[Route("bikes")]
public ActionResult Index()
{
    //here I want to set up if else depending on if cars got called or bikes
    return View();
}

In the index function, I wanna know through some if else which route got called. Maybe using view bag or something?

mfabel
  • 178
  • 1
  • 12
  • Does this answer your question? [How do I get the full url of the page I am on in C#](https://stackoverflow.com/questions/40680/how-do-i-get-the-full-url-of-the-page-i-am-on-in-c-sharp) – mfabel Dec 13 '21 at 18:16
  • I you need different logic, then use different actions. refactor the commonalities in to separate methods – phuzi Dec 14 '21 at 10:31

1 Answers1

0

The request context should have all the information you need.

[HttpGet]
[Route("cars")]
[Route("bikes")]
public ActionResult Index()
{
    var requestUri = Context.Request.Url.AbsoluteUri;

    return View();
}

Here are the relevant documentation pages:

mfabel
  • 178
  • 1
  • 12