Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have an existing project which is using this concept@inherits UmbracoViewPage<LandingViewModel>
My problem now is I'm failing to understand where exactly LandingViewPage is located, where it comes from, and how this concept really works. Forgive me I'm really new to ASP.NET and Umbraco.
Thanks in advance.
Generally this follows this type of structure with MVC and Umbraco:
your model would be: YourDoctypeNameViewModel.cs
your controller would be: YourDoctypeNameController.cs
your view would be: YourDoctypeName.cshtml
Your view file will then inherit from UmbracoViewPage<YourDoctypeNameViewModel>
Umbraco uses its route-hijacking explained here:
to know that for your doctype it should use the YourDoctypeNameController.cs controller to render that particular route (this is all based on the naming, as it is the same as your doctype) so then in your controller you will need to return your view passing the YourDoctypeNameViewModel.cs model data to it
alternatively if you want to access just page data and need no custom model properties or logic in the controller, you could use models builder which allows you to skip the controller step
Thank you for very much, now I have light. Do you have any specific posts or tutorials which might help me to understand models builder. It seems like this concept was used on this project I'm working on.
I managed to follow the steps you mention above using ModelsBuilder module, but I'm still getting the error "The type or namespace name 'LandingViewModel' could not be found (are you missing a using directive or an assembly reference?)". Any help?
I would recommend this walkthrough:
and the documentation: https://our.umbraco.com/documentation/Reference/Templating/Modelsbuilder/Introduction
So if you are using models builder you will probably want to change you view to inherit
You saved my life!
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted