I am currently converting an MVC web page to Umbraco. The web page has various controllers and views:
Controllers
Services
Views
Services
Index
CustomSoftwareDevelopment
I need to be able to render these views as such:
localhost:8080/Services/ (*Redirects to Index)
localhost:8080/Services/CustomSoftwareDevelopment
I also need to be able to use the Document Types and Templates for my views.
How can I accomplish this?
Here's what I've tried:
Simply renaming the content page to Services/CustomSoftwareDevelopment doesn't work as Umbraco renames the page to servicescustomsoftwaredevelopment.
Route Hijacking (https://our.umbraco.org/documentation/reference/routing/custom-controllers) But I am unable to render views created in Umbraco. I can render Views in my Views folder, users also need to be able to edit these views as Templates. Is there a way I can render views created in Umbraco by referencing some Umbraco HTML helper? (i.e. @Umbraco.RenderView("CustomSoftwareDevelopment")?
Routing via Template - This would work, but I lose the template - document type relationship. If I have one document type and five templates, is the one document type supposed to a conglomeration of the possible properties the five templates could have?
I know your converting an MVC web page to Umbraco, but does this page contain functionality, or does it just display content ?
If they are just content pages, and you don't need any controller logic to run, then you can create a content item called 'Services' at the root of your site, that will have a 'Services' template, that contains your index html.
Then underneath this Services page, you can create your content pages, eg CustomSoftwareDevelopment, and the url for this will then be /Services/CustomSoftwareDevelopment ...
that will return the view that the current page has been published with, and you can use ?altTemplate=alternativetemplatealias on the querysting (or the cleaner /myfolder/mypage/alternativetemplatealias) to force the page to be displayed with a different template.
or you can return other Umbraco templates by specifying the path to the razor file eg
Creating MVC Style Views Using Umbraco Templates
I am currently converting an MVC web page to Umbraco. The web page has various controllers and views:
I need to be able to render these views as such:
I also need to be able to use the Document Types and Templates for my views.
How can I accomplish this?
Here's what I've tried:
Hi Mitch
I know your converting an MVC web page to Umbraco, but does this page contain functionality, or does it just display content ?
If they are just content pages, and you don't need any controller logic to run, then you can create a content item called 'Services' at the root of your site, that will have a 'Services' template, that contains your index html.
Then underneath this Services page, you can create your content pages, eg CustomSoftwareDevelopment, and the url for this will then be /Services/CustomSoftwareDevelopment ...
If you need to run the request through your Services controller to perform some kind of logic, combined with Umbraco content then you could create a custom route: https://our.umbraco.org/documentation/reference/routing/custom-routes There is a technique described here to create a virtual node route handler: http://shazwazza.com/post/custom-mvc-routes-within-the-umbraco-pipeline/ that would enable you to fire your custom logic and also pull back content from Umbraco to display your pages.
In terms of what you've tried:
1) There is a little know magic umbraco property called umbracoUrlAlias - if you add this to your content document type, it will enable you to specify alternative urls for your content item: (including folders) https://our.umbraco.org/wiki/reference/umbraco-best-practices/umbracourlalias/
2) When route hijacking there is a helper
return CurrentTemplate(model);
that will return the view that the current page has been published with, and you can use ?altTemplate=alternativetemplatealias on the querysting (or the cleaner /myfolder/mypage/alternativetemplatealias) to force the page to be displayed with a different template.
or you can return other Umbraco templates by specifying the path to the razor file eg
return View("~/views/myotherumbracotemplate.cshtml",model)
I don't know if that random blast of info helps you in the right direction ?
regards
Marc
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.