Copied to clipboard

Flag this post as spam?

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


  • Simon 692 posts 1068 karma points
    Apr 01, 2016 @ 16:00
    Simon
    0

    Custom Model In Index ActionMethod - Returing it parsed as IMasterModel

    Hi,

    I have encountered a problem where I have a controller and have Index ActionMethod, like the following:

    public override ActionResult Index(RenderModel model)
            {
                //var url = this.Umbraco.UmbracoContext.RoutingContext.UrlProvider.
    
                var umbraco = _umbracoControllerWrapperService.GetUmbracoHelperForUmbracoController(this);
                var redirectUrl =
                    _getBoatSearchRedirectUrlIfCategoriesOrActivitiesInQuerystringService
                        .GetBoatSearchResultsFriendlyRedirectUrlFromCurrentRequest(umbraco);
                if (string.IsNullOrWhiteSpace(redirectUrl))
                {
    
                    var boatSearchParameters =
                        _pageService.GetHttpContextItemAndIfEmptyLoadItAndStoreIt(
                            ConstantValues.BoatSearchParameters_HttpContext_Item_Key,
                            getBoatSearchParametersForCurrentPageUrl);
    
                    var boatResults = _boatSearcherService.Search(umbraco, boatSearchParameters);
    
                    var boats = new BoatSearchResultsModel(model.Content);
                    boats.CategoryOrActivity =
                        _boatSearchResultsLoadCategoryOrActivityFromSearchParametersService
                            .LoadCategoryOrActivityFromSearchParametersIfOnlyOneSet(umbraco,
                                boatSearchParameters);
                    boats.BoatSearchResults = boatResults;
                    boats.SearchParameters = boatSearchParameters;
                    boats.SeoTexts =
                        _generateSeoTextsForBoatSearchParametersOrPageService.GenerateSeoTextsForBoatSearchParametersOrPage(
                            umbraco,
                            boatSearchParameters,
                            boats.CategoryOrActivity);
    
    
                    var newRm = new RenderModel(boats);
    
                    return _umbracoControllerWrapperService.CallBaseIndexMethod(this, newRm);
                }
                else
                {
                    //Redirect ot it
                    return RedirectPermanent(redirectUrl);
                }
    

    Seeing the above code, how can I return the model to be parsed as well to IMasterModel, since my master page is accepting IMasterModel and I can set the View to accept: @inherits Umbraco.Web.Mvc.UmbracoViewPage<>

    Any idea please?

    Kind Regards

  • Robert Lundberg 14 posts 60 karma points
    May 17, 2016 @ 11:02
    Robert Lundberg
    0

    Hi,

    Have U looked at the best practises project on github here: https://github.com/jbreuer/Hybrid-Framework-for-Umbraco-v7-Best-Practises

    Couldn't you use a partial class that holds your "extended" view data. and populate the extra view data from the hijacked controller just as the home page or Newsoverview page does.

    // Regards, Robert

Please Sign in or register to post replies

Write your reply to:

Draft