Sitecore MVC Model.Item

I am using MVC in Sitecore and added below code to get the latest updated date.

I maintain one example for this code, they said Model.Item is to keep track of a context item field as data source. But I don't understand what Model.Item is working , because if I remove the Model.Item object, the result is the same.

This page was last modified on: @Html.Sitecore().Field("__Updated", Model.Item, new { format = "dd/mm/yyyy" })


Also, is it possible to use webForms (.ascx) in placeholders generated by webPage (.cshtml)? I have many sublayouts created by webforms and they would like to use them in a .cshtml layout. How do I use them?


source to share

2 answers

Model.Item == Context.Item?

As Jim-Noilsh pointed out, if your code is run based on the current context item, it will default to the same as Model.Item. However, if you are creating data source-based components, or have changed the bound item on the model using a controller, you will need to use Model.Item to ensure that the item is bound to the model, not the context item.

Web Forms Inside MVC Layout?

As far as web forms inside MVC layout go, I don't believe Sitecore supports this out of the box. You can look at some of the tweaks others have made to do something like this ( MVC inside web forms ). It essentially boils down to setting up pipelines to handle incompatible components.

Sitecore Hybrid Solutions

You can also create a hybrid site with some pages in Web Forms and some in MVC, but this may require translating some of your components from one to another. I recently wrote a post on hybrids:

For a hybrid approach, if you want similar functionality for both types of layout, then yes, you will need "duplicate" components (one sub-tier, one render). This is perfectly acceptable. You already have different layouts and templates, it's just another layer. You may have included some presentation business logic in your subwords as well. Maybe you should consider moving this to the ViewModel class and then using the same class in both render and sub-block

Using the ViewModel

For your Model.Item, instead of using the default Sitecore element for your model, you can specify a business object to be the model object. I have a SlideShare to convert WebForms subtasks to MVC rendering . Slide 6 shows an example of a ViewModel implementation, and Slide 8 shows its use in an MVC view. From here, you can probably use the same ViewModel behind your sub-job to centralize some of your logic.




will use the current context element if you don't specify anything. Most likely yours Model.Item == Sitecore.Context.Item




All Articles