3
votes

I'm using MVC in Sitecore and added below code to get last updated date.

I fellow one of example for this code, they said that Model.Item is to track the field of context item as datasource. But, I don't clearly understand what Model.Item works for 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" })

Additionally, is it possible to use webForms (.ascx) on the placeholders created by webPage (.cshtml)?? I have many sublayouts created by webforms and would like to use them in .cshtml layout. How to use them??

2

2 Answers

1
votes

@Html.Sitecore().Field will use the current context item if you don't specify something. Most likely, your Model.Item == Sitecore.Context.Item.

1
votes

Model.Item == Context.Item?

As @Jim-Noellsch mentioned, if your code is running based on the current context item, then the default will be the same as the Model.Item. However, if you are building datasource-driven components or have altered the bound item on the model using a controller, you will want to use Model.Item to ensure you pull the item bound to the model, and not the context item.

Web Forms inside MVC layout?

As for web forms inside an MVC layout, I do not believe that Sitecore supports this out of the box. You can view some customizations that have been done by others to do something similar (MVC inside web forms). Essentially, this comes down to customizing the pipelines to allow your incompatible components to be processed.

Hybrid Sitecore solutions

You can also build a hybrid site with some pages in Web Forms and some in MVC, but this may require you to translate some of your components from one to the other. I recently wrote a post on hybrids here: http://www.nonlinearcreations.com/Digital/how-we-think/articles/2015/05/MVC-Web-Forms-Hybrid-Sitecore.aspx

For a hybrid approach, if you need to have similar functionality on both layout types, then yes, you will need 'duplicate' components (one sublayout, one rendering). This is completely acceptable. You already have different layouts and templates, this is just another layer. You may also have put some presentation business logic in your sublayouts. You may want to think about moving that to a ViewModel class and then using the same class in both your rendering and sublayout

Using ViewModel

For your Model.Item, instead of using a standard Sitecore Item for your Model, you can specify a business object that will be the model object instead. I have a SlideShare on converting WebForms sublayouts to MVC renderings. Slide 6 shows a ViewModel implementation example, and Slide 8 shows using it in an MVC View. From here, you could probably use the same ViewModel behind your sublayout to centralize some of your logic.