开发者

ASP.NET MVC controller Index action cannot be loaded without adding Index to URL

This problem began today and I have no idea why! I have a controller named "Course" which has an Index action. So generally, I should be able to view the page just by navigating to http://domain.com/Course. But as of today, I get a resouce cannot be found page if I don't include 'Index' in the URL i.e. http://domain.com/Course/Index.

My course controller:

[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 code behind:

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);
        }

Any ideas what's going on?


Does it not need the HttpGet attribute decoration [AcceptVerbs("GET")] as it is with the details action.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜