tags:

views:

58

answers:

2

For the controller below, why does a call to http://localhost%3Aport/content/about not pass "about" as the value for the page parameter of the index controller? Default routing. Clearly I do not understand routing...

    public class ContentController : Controller
    {
        private IContentService _service;

        public ContentController()
            {
                _service = new ContentService(new ModelStateWrapper(this.ModelState), new ContentRepository());
            }


        public ActionResult Index(string page)
        {
            return RedirectToAction("View", new { p = page });
        }
        public ActionResult Page(string p)
        {    
            ContentPage contentPage = _service.GetPageContent(site, p);
            return View(contentPage);
        }
}
+1  A: 

Default routing presumes you are using the following pattern: {action}/{id}. You are not using this. You need to re-declare your route so that it sends everything to the "Index" action and passes the "p" parameter.

Wyatt Barnett
Thank you. I did not realize it was the name of the parameter that did it. I thought it was just whatever was passed first.
Ten Ton Gorilla
A: 

Are you running IIS6? If so, make sure you map the asp.net isapi dll to the .mvc extension.

Routing was killing me last week until I found this out...

Mark Kadlec
I personally default it to .aspx. Less work when deploying.
Min