Getting Index to accept optional parameters from route
<p>I have this in my <em>Startup.cs</em> file:</p>

<pre><code>        app.UseMvc(routes =&gt;
        {
            routes.MapRoute(
                name: "list",
                template: "{controller=List}/{action=Index}/{username?}");
        });
</code></pre>

<p>I want this:</p>

<blockquote>
  <p>/list/</p>
</blockquote>

<p>to return a view.</p>

<p>and this:</p>

<blockquote>
  <p>/list/random_username.12334</p>
</blockquote>

<p>to return another view.</p>

<p>I have this in my <em>ListController.cs</em>:</p>

<pre><code>    public IActionResult Index(string username)
    {
        if (String.IsNullOrEmpty(username))
        {
            ViewData["Message"] = "user index";
        } else {
            ViewData["Message"] = "Hello " + username;
        }

        return View();
    }
</code></pre>

<p>But only the index without parameters work. The other one returns 404. </p>