ASP.Net MVC route mapping

前端 未结 5 1802
独厮守ぢ
独厮守ぢ 2021-01-11 10:19

I\'m new to MVC (and ASP.Net routing). I\'m trying to map *.aspx to a controller called PageController.

routes.MapRoute(
   \"Pa         


        
5条回答
  •  北海茫月
    2021-01-11 11:01

    Not sure how your controller looks, the error seems to be pointing to the fact that it can't find the controller. Did you inherit off of Controller after creating the PageController class? Is the PageController located in the Controllers directory?

    Here is my route in the Global.asax.cs

    routes.MapRoute(
        "Page", 
        "{Page}.aspx", 
        new { controller = "Page", action = "Index", id = "" }
    );
    

    Here is my controller, which is located in the Controllers folder:

    using System.Web.Mvc;
    
    namespace MvcApplication1.Controllers
    {
        public class PageController : Controller
        {
            public void Index()
            {
                Response.Write("Page.aspx content.");
            }
        }
    }
    

提交回复
热议问题