Routes and parameters using custom tree and MVC not Angular
I have a situation where I have decided to leverage MVC contollers and views instead of Angular as I have a lot of existing code that I need to port in to an Umbraco solution. I have had some succsess doing this by mapping the routes and forcing it to use a MCV controller which renders a MVC view - everything is working well, the create and edit views hit the controller and render the ASP.NEt MVC view! Happy days, apart from one issue...
Take a look at the following route mapping and you will see that I am looking for edit.html/{id} - however the ID is never returned to my controller - I susspect it is because the actual URL hit does not contain the id param...can anybody confirm this and is so offer a way that I can ensure that I can read the ID on my controller (and this is a MVC controller not an Angular controller).
routes.MapRoute(
name: "TestEdit",
url: "App_Plugins/test/backoffice/testitem/edit.html/{id}",
defaults: new { controller = "test", action = "Edit", id = ""}
);
Angular uses templates that are rendered in the browser, and doesnt support serverside processing, you can only return a single instance of a template, not different templates based on different IDs.
This is because the templating and logic happens in the browser, which means we can cache things quite effectively and make the application really fast. By trying to cram server-rendered html into the angular templating system you are trying to break a fundamental thing in angular.
The alternatives are to load in the views through the legacy iframe based approach or look into converting your views into angular that then load data from your mvc controllers as mvc - depending on project size, time available etc, I would recommend that you do the angular conversion.
As an aside, personal opnion here! but Umbraco is an ASP.NET MVC CMS....whats with the use of a Javascript MVC framework!? The application is sat smack on top of the .NET stack....its a really strange direction to take.
@Per / Umbraco HQ: What is the main reason for using Angular instead of ASP.NET MVC for doing the main backend templating etc. What are the advantages of NOT using MVC Views (.cshtml, and all the helpers available there), but plain HTML/JS views with Angular? Is it just for performance? How are your experiences with that application model so far (maintenance, extensibility, clearness..)?
i work with telerik also ... and they have amazing helpers that i also extended .. with this new aproach i had to reorganize all the code .. and throw away hours of really nice MVC helpers ...that gives you all with one line of code
... with angular ... lets start building the wheel again ... :(
You can still use your MVC views but then you need to change the way you render the tree for your custom section. I guess you now inherit your tree from a class Umbraco.Web.Trees.TreeController. This is the new tree controller introduced in v7 and is meant to be used with angular.
You can still you use the v6 style trees. But than you need to inherit your custom tree class from umbraco.cms.presentation.Trees.BaseTree
You can find a lot of examples online on how to create a custom section that way for example this blogpost by Tim Geyssens : http://www.nibble.be/?p=250
Thank you for your post ... but that one i already know how to do it and that is a view ... what about a plugin ? or a datatype ? i searched and searched ...could find any documentation on that for U7 ...do you know how to do it or any place where i can get that ?
Routes and parameters using custom tree and MVC not Angular
I have a situation where I have decided to leverage MVC contollers and views instead of Angular as I have a lot of existing code that I need to port in to an Umbraco solution. I have had some succsess doing this by mapping the routes and forcing it to use a MCV controller which renders a MVC view - everything is working well, the create and edit views hit the controller and render the ASP.NEt MVC view! Happy days, apart from one issue...
Take a look at the following route mapping and you will see that I am looking for edit.html/{id} - however the ID is never returned to my controller - I susspect it is because the actual URL hit does not contain the id param...can anybody confirm this and is so offer a way that I can ensure that I can read the ID on my controller (and this is a MVC controller not an Angular controller).
I think this will end in tears Dave :)
Angular uses templates that are rendered in the browser, and doesnt support serverside processing, you can only return a single instance of a template, not different templates based on different IDs.
This is because the templating and logic happens in the browser, which means we can cache things quite effectively and make the application really fast. By trying to cram server-rendered html into the angular templating system you are trying to break a fundamental thing in angular.
The alternatives are to load in the views through the legacy iframe based approach or look into converting your views into angular that then load data from your mvc controllers as mvc - depending on project size, time available etc, I would recommend that you do the angular conversion.
I will ditch for version 6 :) There is a lack of support and documentation for 7 and it means learning a lot of new things. Deadlines wont allow :)
As an aside, personal opnion here! but Umbraco is an ASP.NET MVC CMS....whats with the use of a Javascript MVC framework!? The application is sat smack on top of the .NET stack....its a really strange direction to take.
Hi,
I would like to revive this discussion:
@Per / Umbraco HQ: What is the main reason for using Angular instead of ASP.NET MVC for doing the main backend templating etc. What are the advantages of NOT using MVC Views (.cshtml, and all the helpers available there), but plain HTML/JS views with Angular? Is it just for performance? How are your experiences with that application model so far (maintenance, extensibility, clearness..)?
Best Regards Andreas
I'm also curious about that reason :)
i work with telerik also ... and they have amazing helpers that i also extended .. with this new aproach i had to reorganize all the code .. and throw away hours of really nice MVC helpers ...that gives you all with one line of code
... with angular ... lets start building the wheel again ... :(
sorry its just an humble opinion ...
AS
Hi Dave,
You can still use your MVC views but then you need to change the way you render the tree for your custom section. I guess you now inherit your tree from a class Umbraco.Web.Trees.TreeController. This is the new tree controller introduced in v7 and is meant to be used with angular.
You can still you use the v6 style trees. But than you need to inherit your custom tree class from umbraco.cms.presentation.Trees.BaseTree
You can find a lot of examples online on how to create a custom section that way for example this blogpost by Tim Geyssens : http://www.nibble.be/?p=250
Dave
Thank you for your post ... but that one i already know how to do it and that is a view ... what about a plugin ? or a datatype ? i searched and searched ...could find any documentation on that for U7 ...do you know how to do it or any place where i can get that ?
thank you
AS
What do you mean with a Plugin ?
Property editors should be created using angular in V7. See linsk below for documentation and tutorials
http://our.umbraco.org/documentation/Extending-Umbraco/Property-Editors/property-editors-v7
http://umbraco.github.io/Belle/#/tutorials/CreatingAPropertyEditor
Dave
2017 and this I am having this exact discuission in my head. I want to use MVC and it seems like you can, but with a bit of extra effort.
Even though MVC is my strongest skill set I think its about time to bite the bullet and go agualr.
Wish me luck!
is working on a reply...