加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – Umbraco Surface Controller或RenderMvcControll

发布时间:2020-12-16 07:01:11 所属栏目:asp.Net 来源:网络整理
导读:嗨,我有’home’控制器和umbraco 7中的’sort’控制器.’home’控制器可以正常处理索引操作,因为它是从RenderMvcController重写的.首先,我很困惑我应该在哪种控制器中使用哪种控制器,即表面控制器或rendermvccontroller.我似乎无法访问下面的twitter动作,这
嗨,我有’home’控制器和umbraco 7中的’sort’控制器.’home’控制器可以正常处理索引操作,因为它是从RenderMvcController重写的.首先,我很困惑我应该在哪种控制器中使用哪种控制器,即表面控制器或rendermvccontroller.我似乎无法访问下面的twitter动作,这是我需要的ajax.我是否需要将twitter动作放在表面控制器中,还是可以在umbraco中使用常规的mvc控制器?

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

解决方法

我的方法是:

>渲染控制器仅用于向用户显示数据.
>表面控制器用于交互(我使用它主要用于交互ajax或表单)

要呈现子操作,您可以使用以下示例:

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

更新:
要实现自定义路由,您可以查看

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读