Asp.net mvc 2 如果不向URL添加索引,则无法加载ASP.NET MVC控制器索引操作
这个问题从今天开始,我不知道为什么!我有一个名为“课程”的控制器,它有一个索引操作。因此,一般来说,我应该能够通过导航到来查看页面。但是到今天为止,如果我没有在URL中包含“索引”,我会得到一个“资源找不到”页面,即 我的课程控制员:Asp.net mvc 2 如果不向URL添加索引,则无法加载ASP.NET MVC控制器索引操作,asp.net-mvc-2,Asp.net Mvc 2,这个问题从今天开始,我不知道为什么!我有一个名为“课程”的控制器,它有一个索引操作。因此,一般来说,我应该能够通过导航到来查看页面。但是到今天为止,如果我没有在URL中包含“索引”,我会得到一个“资源找不到”页面,即 我的课程控制员: [HandleError] public class CourseController : Controller { OIEPRepository repo = new OIEPRepository(); publ
[HandleError]
public class CourseController : Controller
{
OIEPRepository repo = new OIEPRepository();
public ActionResult Index()
{
var courses = repo.GetCourseCategoriesByCulture(SiteGlobals.UICulture).ToList();
return View(courses);
}
[AcceptVerbs("GET")]
public ActionResult Detail(int id)
{
var course = repo.GetCourseById(id);
if (course != null)
return View(course);
else
return RedirectToAction("Index");
}
}
My Global.ascx代码隐藏:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
/*routes.MapRoute(
"Detail",
"{controller}/{id}",
new { controller = "Course", action = "Detail", id = 0 }
);*/
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
知道发生了什么吗?它不需要HttpGet属性修饰[AcceptVerbs(“GET”)],因为它与details操作一样。它不需要HttpGet属性修饰[AcceptVerbs(“GET”)],因为它与details操作一样。您显示的代码应该可以工作。问题出在别的地方。所以,如果这个问题是从今天开始的,你可以简单地对你的VCS中的源代码做一个比较,并比较它从昨天开始工作以来发生的变化。嗯,我也这么认为。我做了很多改变。我主要添加了GalleryServerPro模块。您显示的代码应该可以工作。问题出在别的地方。所以,如果这个问题是从今天开始的,你可以简单地对你的VCS中的源代码做一个比较,并比较它从昨天开始工作以来发生的变化。嗯,我也这么认为。我做了很多改变。我主要添加了GalleryServerPro模块。