Pranay
Pranay

Reputation: 452

Can we create a View with model in sitecore without creating a Controller?

Is it possible to create a View with a model but without creating any controller in Sitecore MVC 7.2.

Upvotes: 1

Views: 966

Answers (2)

Zooking
Zooking

Reputation: 3521

If you want to do this the "plain" Sitecore way. Just right-click the item "Sitecore/layout/renderings" and insert an item of type "View Rendering". Add the path of your view in the "path"-field.

This video is a very good introduction to Sitecore MVC http://youtu.be/i3Mwcphtz4w

This is also a very good source for learning about Sitecore MVC: http://sitecore-community.github.io/docs/

Upvotes: 1

Ruud van Falier
Ruud van Falier

Reputation: 8877

Yes, you can.
It's easiest with Glass Mapper, but you can do it out of the box as well.

Glass implements a processor in the mvc.getModel pipeline that looks for the model type in the View Rendering definition and creates an instance for you before executing the view.
See this tutorial for an example.

Out of the box you can create a Model item underneath /sitecore/Layout/Models that refers to a class.
You can then select the model item in model field of your View Rendering.

Upvotes: 1

Related Questions