Copied to clipboard

Flag this post as spam?

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


  • Stephanie 39 posts 101 karma points
    Jun 20, 2016 @ 15:45
    Stephanie
    0

    Issue with View returned from Custom Controller

    I have a custom controller with an Index method that could possibly return multiple views depending on information passed in. I've noticed that no matter what view I return from the method, it always ends up going back to the default view (based on the editor name).

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Jun 20, 2016 @ 15:56
    Alex Skrypnyk
    0

    Hi Stephanie,

    Can you shoe code of your controller?

    Thanks, Alex

  • Stephanie 39 posts 101 karma points
    Jun 20, 2016 @ 16:26
    Stephanie
    0
    using System.Linq;
    using System.Web.Mvc;
    using Lecoati.LeBlender.Extension.Controllers;
    using Lecoati.LeBlender.Extension.Models;
    using Umbraco.Core.Models;
    
    namespace marathon.Web.Controllers.Grid
    {
        public class WidgetPickerController : LeBlenderController
        {
            public ActionResult Index(LeBlenderModel model)
            {
                var item = model.Items.First();
                int contentId = 0;
                if (item != null && item.GetValue("widget") != null && int.TryParse(item.GetValue("widget").ToString(), out contentId) && contentId > 0)
                {
                    IPublishedContent node = Umbraco.Content(contentId);
                    if (node != null && node.Id > 0)
                    {
                        return View("~/Views/Partials/Grid/Editors/Widget/" + node.DocumentTypeAlias + ".cshtml", node);
                    }
                }
                return View(model);
            }
        }
    }
    
  • Jason Espin 368 posts 1335 karma points
    Jun 20, 2016 @ 17:17
    Jason Espin
    0

    Hi Stephanie,

    Could you run this in debug with a breakpoint within your if statement to see if that return statement fires?

    if (node != null && node.Id > 0)
                    {
                        return View("~/Views/Partials/Grid/Editors/Widget/" + node.DocumentTypeAlias + ".cshtml", node);
                    }
    

    Cheers,

    J

  • Stephanie 39 posts 101 karma points
    Jun 20, 2016 @ 17:36
    Stephanie
    0

    I have debugged the code and it does fire the return statement.

    Actually, since posting the question, I've looked at the source code for LeBlender. In the LeBlenderController.cs file, line 66 and 67 (shown below) it's overwriting the view returned by the custom controller.

    // Return the action result 
    actionResult.ViewName = frontView;
    
Please Sign in or register to post replies

Write your reply to:

Draft