【发布时间】:2016-07-13 17:01:57
【问题描述】:
我的 Startup.cs 文件中有这个:
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 你是什么意思?
标签: c# .net asp.net-mvc asp.net-core-mvc asp.net-core-1.0