我有這個接受可選參數:獲取指數在我<em>Startup.cs</em>文件從路線
app.UseMvc(routes =>
{
routes.MapRoute(
name: "list",
template: "{controller=List}/{action=Index}/{username?}");
});
我想這一點:
/列表/
到返回一個視圖。
這:
/list/random_username.12334
返回另一個視圖。
我有這個在我ListController.cs:
public IActionResult Index(string username)
{
if (String.IsNullOrEmpty(username))
{
ViewData["Message"] = "user index";
} else {
ViewData["Message"] = "Hello " + username;
}
return View();
}
但只有不帶參數的指標工作。另一個返回404.
你的模式需要'/ Index'。 – SLaks
@SLaks你是什麼意思? – Cornwell