Copied to clipboard

Flag this post as spam?

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


  • Alex Frost 2 posts 72 karma points
    15 days ago
    Alex Frost
    0

    Route Hijack with PartialView

    Good Morning,

    Just wondering if this is at all possible. I have the below method which works fine, but my issue is calling an Html.RenderAction within this page, that inherits the page Model, to bring back data from the DocumentType.

    public class EventsController : Umbraco.Web.Mvc.RenderMvcController
    {
        public EventsController()
        {
            public ActionResult Index(ContentModel model)
            {
                var eventsViewModel = new EventsViewModel(model.Content)
                {
                }
    
                return CurrentTemplate(eventsViewModel);
            }
        }
    }
    
    public class EventsViewModel : PublishedContentWrapped
    {
        public EventsViewModel(IPublishedContent content) : base(content) { }
    }
    

    Somehow, I need to get the Model data, from the above page, into this below ActionResult

    public class CMSEventsController : Umbraco.Web.Mvc.SurfaceController
    {
        public ActionResult GetLatestEvents(String partialView)
        {
            var latestEventsViewModel = new LatestEventsViewModel()
            {
    
            };
    
            return PartialView($"~/Views/Partials/{partialView}", latestEventsViewModel);
        }
    }
    

    I call the below on the main Events page.

    @{
      Html.RenderAction("GetLatestEvents", "CMSEvents", new { partialView = "_LatestEvents.cshtml" });
    }
    

    I probably haven't explained this very well!!

    Best Regards

Please Sign in or register to post replies

Write your reply to:

Draft