MVC - Retrieve values from a URL

by
Jeremy Canfield |
Updated: March 20 2020
| MVC articles
In this example, let's say we want to display something unique based on the id value in the URL. For example, let's say we have these two URLs:
- www.example.com/MVC/Home/Index?username=Jeremy
- www.example.com/MVC/Home/Index?username=Natalie
When Jeremy is requested, we want to display "Welcome Jeremy". When Natalie is requested, we want to display " Welcome Natalie" Add the following to Index string of the HomeController class:
public string Index(string username)
{
return "Welcome " + username;
}
Did you find this article helpful?
If so, consider buying me a coffee over at