【发布时间】:2013-12-19 15:27:13
【问题描述】:
我有一个非常简单的 MVC 应用程序:
当我输入时:
http://locahost:8080
routeconfig 中的以下路由将我带到 Home 控制器:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
当我输入以下内容时,我收到 404 错误。
http://locahost:8080/JohnDoe
我想将此请求映射到 Home Controller 的 Get Action with name 函数(见下文)。我该怎么做呢?
public Person Get(string name)
{
PersonRespository db = new PersonRespository();
return db.GetPerson(name);
}
非常感谢各位。
【问题讨论】:
-
您的操作名称是 Index,但您的方法称为 Get。调用你的方法 Index。
标签: c# .net asp.net-mvc routing