It can depend on what you are trying to achieve. If you need to take control of custom routes then you'll probably need to use 'Areas', if not then you don't need them to be able to implement your own custom controllers.
Thanks for the reply, Jon.Sorry it took a little bit of time to reply you.
I am using surface controllers currently.The problem now after using it I am calling the httppost action method on form post which is getting called but I want to redirect it to a strongly typed partial view.
I was trying to return the partial view in the following fashion:
Firstly it throws me an error that "Inherits and model keyword cannot be used together".
Can you please help me out where am I lacking in my approach?I am also not getting how to use ChildActionOnly Attribute for the action methods and the reason for using it?
If the same method is decorated with the 'ChildActionOnly' attribute then you cannot request it by the URL, you can only call it from within another View using Html.Action or Html.RenderAction. It's just a way to allow you to separate your programming logic into individual methods to control discrete parts of a View - this is how they are used in Umbraco 5 as Surface Controllers.
"The model item passed into the dictionary is of type 'xyz.Areas._base.ViewModel.XYZViewModel', but this dictionary requires a model item of type 'Umbraco.Cms.Web.Model.Content'."
On line:@Html.Partial("contentPartial")
In order to solve that I created an Action Method in my SurfaceController with the Attribute ” [ChildActionOnly]” which will return the content Partial View.
But for calling that I created a macro and inserted that macro in my template. Role of that macro will be to render that child action right?
The problem I am facing is, inserting macro in the place of RightPanel partial throws error:
The type or namespace name 'RenderMacro' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
Line : @Umbraco.RenderMacro("rightPanel", new { defaultRedirectId = "content$empty_root$$_p__nhibernate$_v__guid$_f527fff3255344afb409a05400b6cc4d" })
Can you help me out, what could be the probable cause of the error and How should I approach in order to fix it?
How to Structure Controllers in the Umbraco MVC3 Application?
Hello Everyone,
I am struggling with structuring of the controllers and models in the Umbraco MVC3 Application.
Can anyone help me out where to place the controllers in the application so that the action methods in Controllers redirect to the appropriate views?
I want action links in navigation pane to which have action methods associated with them to return their corresponding views.
Are the controllers and models to be placed under area folder?
I will be really grateful if I could get sample example or project which illustrates or depicts, well formed structure of Umbraco MVC3 Application.
Thanks and Regards.
Nitesh
I am using Umbraco 5 for the same.
It can depend on what you are trying to achieve. If you need to take control of custom routes then you'll probably need to use 'Areas', if not then you don't need them to be able to implement your own custom controllers.
You can use 'Surface Controllers' (a good article can be found here: http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-5-Surface-Controllers.aspx) with Macros and create strongly typed views for your Model and it works very well.
Thanks for the reply, Jon.Sorry it took a little bit of time to reply you.
I am using surface controllers currently.The problem now after using it I am calling the httppost action method on form post which is getting called but I want to redirect it to a strongly typed partial view.
I was trying to return the partial view in the following fashion:
And then on the view I am making it strongly typed in the following fashion:
Firstly it throws me an error that "Inherits and model keyword cannot be used together".
Can you please help me out where am I lacking in my approach?I am also not getting how to use ChildActionOnly Attribute for the action methods and the reason for using it?
Thanks.
You can have either the @inherits or the @model directive at the top of your Razor view, but not both (so I'd get rid of the @inherits line).
ChildActionOnly is used to prevent controller methods from being executed directly e.g in a normal MVC application you might have something like this:
This will correspond to a URL: http://localhost/MyController/DoSomething
If the same method is decorated with the 'ChildActionOnly' attribute then you cannot request it by the URL, you can only call it from within another View using Html.Action or Html.RenderAction. It's just a way to allow you to separate your programming logic into individual methods to control discrete parts of a View - this is how they are used in Umbraco 5 as Surface Controllers.
Jon,
Thanks for the reply.
I am getting the following error in my view:
"The model item passed into the dictionary is of type 'xyz.Areas._base.ViewModel.XYZViewModel', but this dictionary requires a model item of type 'Umbraco.Cms.Web.Model.Content'."
On line:@Html.Partial("contentPartial")
In order to solve that I created an Action Method in my SurfaceController with the Attribute ” [ChildActionOnly]” which will return the content Partial View.
But for calling that I created a macro and inserted that macro in my template. Role of that macro will be to render that child action right?
The problem I am facing is, inserting macro in the place of RightPanel partial throws error:
The type or namespace name 'RenderMacro' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
Line : @Umbraco.RenderMacro("rightPanel", new { defaultRedirectId = "content$empty_root$$_p__nhibernate$_v__guid$_f527fff3255344afb409a05400b6cc4d" })
Can you help me out, what could be the probable cause of the error and How should I approach in order to fix it?
Thanks
is working on a reply...