0

So this is my controller :

 [HttpGet("Home/Project-Name/Dashboard")]
  public IActionResult Index()
  {
    ViewBag.Current = "Dashboard";
    return View();
  }

The question is, how do I get the "Project-Name" Value ?

2
  • Is the idea that Index() can be called for any Project-Name, or only one specific name? Commented Feb 20, 2020 at 8:15
  • I just wanna get the project name and send it to my view to decide which navbar that i'll use, because I have a lot of navbar. Commented Feb 20, 2020 at 8:18

2 Answers 2

2
var projectName = HttpContext.Request.Path.Value.Split('/',StringSplitOptions.RemoveEmptyEntries)[1]
Sign up to request clarification or add additional context in comments.

Comments

0

SOLVED.

Using :

@using Microsoft.AspNetCore.Http.Extensions;
String url = @Context.Request.GetDisplayUrl();
var uri = new Uri(url);
String url_project = uri.Segments[2].Replace(@"/", "");

Note that I use this code in view.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.