Domanda

Hi I have my 'home' controller and a 'sort' controller in umbraco 7. The 'home' controller works fine for the index action as it is overridden from RenderMvcController. Firstly I am confused which controller I should using in which instance i.e a surface controller or a rendermvccontroller. I cant seem to access the twitter action below which is something I need for ajax. Do I need to put the twitter action in a surface controller or could I use a regular mvc controller in umbraco?

     public override ActionResult Index(RenderModel model)


       {
            var storedProcedure = new StoredProcedure()
            {
                ConnectionString = ConfigurationManager.ConnectionStrings["CentralDbContext"].ConnectionString
            };

            DataSet ds = storedProcedure.ExecuteProcedureToDataSet("GetHomePage");

            IMapSetup map = new MapHomePage();
            HomePage homepage = map.Setup<HomePage>(ds);


            homepage.Slideshow = CurrentPage.AncestorsOrSelf(1).First().Descendants("SlideshowItem").Take(5).AsMany<Slideshow>();

            this._weatherSettings.DefaultLocation = "warrington";
            homepage.Forecast = new Forecaster(this._weatherSettings, this._cacheHelper).GetWeather(this._weatherSettings.DefaultLocation);

            return CurrentTemplate(homepage);
        }
 public ActionResult TwitterSort(int? page)
    {
        int currentPageIndex = page.HasValue ? page.Value - 1 : 0;

        var storedProcedure = new StoredProcedure()
        {
            ConnectionString = ConfigurationManager.ConnectionStrings["CentralDbContext"].ConnectionString
        };

        DataSet ds = storedProcedure.ExecuteProcedureToDataSet("GetHomePage");

        IMapSetup map = new MapHomePage();
        HomePage homepage = map.Setup<HomePage>(ds);


        if (Request.IsAjaxRequest())
        {
            return PartialView("umbTweets", homepage.Twitter.ToPagedList(currentPageIndex, DefaultPageSize));
        }

        return PartialView(homepage.Twitter.ToPagedList(currentPageIndex, DefaultPageSize));
    }
È stato utile?

Soluzione

My Approach is:

  • Render controller is only for displaying data to user.
  • Surface controller is for interaction (I use this for interaction mainly ajax, or forms)

For rendering child action you can use following example:

http://our.umbraco.org/documentation/Reference/Mvc/child-actions

Update: To implement custom routing you can have a look on

http://cpodesign.com/blog/umbraco-implementing-routing-in-mvc/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top