I have an existing project which is using this concept@inherits UmbracoViewPage<LandingViewModel>
in Views.
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.
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?
Understanding How ViewModel Works
Hello there,
I have an existing project which is using this concept
@inherits UmbracoViewPage<LandingViewModel>
in Views. 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.
Hello,
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: https://our.umbraco.com/documentation/reference/routing/custom-controllers
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
Hi Louis,
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: https://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/
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
Thank you.
You saved my life!
is working on a reply...