Copied to clipboard

Flag this post as spam?

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


  • DarkCoder 19 posts 39 karma points
    Jun 08, 2013 @ 22:52
    DarkCoder
    0

    Child Action in Umbraco 6?

    I'm working with version 6.1. My last experience with Umbraco is version 4 with webforms. So I'm very confused. I can't seem to find any documentation.

    I saw a screenshot from V5 where you could choose a macro type (one choice was Child Action )

    http://parwej.files.wordpress.com/2012/06/untitled.png

    In V6 there is only MVC Partial View. But I want my controller called!

    Can Macros not be used with child actions in V6?

    Am I supposed to just do @Html.Action..... in my template or view? What about macro parameters then?

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 10, 2013 @ 19:50
    Jeavon Leopold
    0

    Hi, did you find the v6 Mvc documentation here?

    You can create a SurfaceController which can return a Partial View and then you can create a Macro Partial View and call your Surface Controller from there, I would suggest reading this excellent blog post which describes doing just this.

    Alternatively, If you want to pass parameters directly to a Mvc Partial view, you can do this by using ViewData.

    e.g.

    @{Html.RenderPartial(
        "MyPartialView", 
        Model.Content,
        new ViewDataDictionary(this.ViewData) { 
            { "param1", "value1" }, 
            {"param2", "value"} 
        }
        );}

    Then in your partial you can retreive the value of the parameter like this:

    ViewData["param1"] 

    Hope that's helpful?

    Thanks,

    Jeavon

  • DarkCoder 19 posts 39 karma points
    Jun 10, 2013 @ 22:42
    DarkCoder
    0

    I'm confused by the terminology used. A partial view is a view with no controller, is my understanding (it's called/referenced from another View). And a View is called by a controller. And a child action is a MVC "Usercontrol", a view placed on another view which has it's own controller method/action.

    well, I tried to create a surfacecontroller with a my own model. But I keep getting an exception stating that it expects a RenderModel.

    If I place this in my View: @inherits Umbraco.Web.Mvc.UmbracoTemplatePage then I get no exception but model does not contain my model variables. How do I use my own model with a surfacecontroller? My google skills are lacking it seems.

    My controller:

        public class CreateUserSurfaceController : Umbraco.Web.Mvc.SurfaceController
        {
            [HttpGet]
            public ActionResult CreateUser()
            {     
                var mymodel = new CreateUserModel();
                return View("~/Views/CreateUser.cshtml", mymodel);
            }
        }

    My View:

    @model CreateUserModel
    @{
        ViewBag.Title = "CreateUser";
        Layout = "Template3Col.cshtml";
    }

     

    ERROR:

    The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'Models.CreateUserModel'.

     

     

     

     

     


     


     

  • DarkCoder 19 posts 39 karma points
    Jun 11, 2013 @ 17:55
    DarkCoder
    0

    Now don't all type at once!

    I can now render my page with a custom model using RenderMvcController. This took HOURS AND HOURS....sigh...

    Layout:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = null;
    }

    Controller:

        public class CreateUserController : Umbraco.Web.Mvc.RenderMvcController
        {
            [HttpGet]
            public override ActionResult Index(RenderModel model)
            {     
                var mymodel = new Models.CreateUserModel();
                return CurrentTemplate(mymodel);
            }
        }

    Custom model:

        public class CreateUserModel : Umbraco.Web.Models.RenderModel
        {
            public CreateUserModel() : this(new UmbracoHelper(UmbracoContext.Current).TypedContent(UmbracoContext.Current.PageId)) { }
            public CreateUserModel(IPublishedContent content, CultureInfo culture) : base(content, culture) { }
            public CreateUserModel(IPublishedContent content) : base(content) { }
            public string UserName { get; set; }
            public string Password { get; set; }
            public string PasswordAgain { get; set; }
        }

    View (my "page"):

    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        Layout = "Template3Col.cshtml";
    }

    I think it's butt ugly that I have to have a RenderModel parameter in my Index method. And my "real" model is now full of RenderModel crap.

    I don't dare think how long it will take me to do a post back :(

     

    Anyway, a question if someone should stumble across this forum some day:

    What is the core difference between RenderMvcController and SurfaceController? Belive me, I HAVE googled. In what situation do I use what?

     

     

     

     

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    Jun 11, 2013 @ 22:52
    Jeavon Leopold
    0

    Hi, I'm no Mvc guru however did you find the official documentation about Custom Controllers (RenderMvcController) and Surface Controllers?

    As I understand it in simple terms, a Surface Controller is used for child actions (returning partial views) and a custom controller is used if you want full control over the page execution.

     

  • DarkCoder 19 posts 39 karma points
    Jun 12, 2013 @ 07:12
    DarkCoder
    0

    Yes, found them.

    What this documentation lacks is a simple example of post back or surface controller using a custom model. Is post back even possible with RenderMvcController? It's not mentioned anywhere. How does it (post back) work with SurfaceController? For one thing SurfaceController can't do: return CurrentTemplate(mymodel). what I did in my code above does not work with surface controller.

    "A SurfaceController is an MVC controller that interacts with the front-end rendering of an UmbracoPage. They can be used for rendering Child Action content, for handling form data submissions and for rendering Child Action macros."


    So RenderMvcController cannot do submissions..or? Seems like SurfaceController can do everything, why even use RenderMvcController? What's the downside of SurfaceController?

    My main view (RenderBody) is not a child action is it? What if I want a form to submit there? If that is not possible that would be really disappointing.


Please Sign in or register to post replies

Write your reply to:

Draft