Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ben Warham 1 post 21 karma points
    Sep 26, 2013 @ 13:15
    Ben Warham
    0

    Problem with RenderMvcController - not calling Index function when no action matches

    I have inherited a site where the home page and main search are based on a controller inheriting from RenderMvcController, which seems to working. Whether it's following recommended practice or not is another matter. The controllers both look similar to the following -

    public class HomePageController : RenderMvcController
    {
        private readonly IDbExecutor _dbConnection;
    
        public HomePageController()
        {
            _dbConnection = new Dapper.Wrapper.SqlExecutor(new SqlConnection(WebConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString));
        }
    
        public ActionResult HomePage()
        {
            using (
                var reader = _dbConnection.QueryMultiple(SimpleSearchModel.PopulateSimpleSearchControlQuery))
            {
                return CurrentTemplate(new HomePageViewModel(reader));
            }
        }
    }
    

    However have since added a new Document Type - ContentPage & associated Template. If I try and access a page of this type a get a 404 error. Thanks to Elmah I have determined that the exception is "A public action method 'ContentPage' was not found on controller 'Umbraco.Web.Mvc.RenderMvcController'.", where content page is the Docuemnt Type.

    I have managed to work around this problem, in a fashion, by creating another Controller, "ContentPage" which also inherits from RenderMvcController

    This currently is as simple as they get and just consists of the following -

    public class ContentPageController : RenderMvcController
    {
        public ActionResult ContentPage(RenderModel model)
        {
            return base.Index(model);
        }
    }
    

    Changing the ContentPage function to -

    public override ActionResult Index(RenderModel model)
    

    results in a similar exception to the first, "A public action method 'ContentPage' was not found on controller 'Cms.Controllers.ContentPageController'."

    So as best I can tell the default action mapping back to Index appears not to be working in either RenderMvcController or my ContentPageController (which inherits from RenderMvcController)

    Does anyone have any ideas what I'm doing wrong?

    Some other info that may or may not be relevant; When this was first noticed it was on version 6.0.5, it has since been upgraded to 6.1.5. Running on .net 4 and IIS 7.5

    Thanks Ben

Please Sign in or register to post replies

Write your reply to:

Draft