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 )
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.
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); } }
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'.
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; } }
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.
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.
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?
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.
Then in your partial you can retreive the value of the parameter like this:
Hope that's helpful?
Thanks,
Jeavon
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'.
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?
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.
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.
is working on a reply...