Search code examples
asp.net-mvcorchardcms

Orchard Module as Partial view


I had created a module named Orchard.Blogs in my application. Now that blogs view can I make it as a partial view to my other views ? For Ex: http://localhost/Orchard.Web/Orchard.HrCompany/Payroll/GetPay is my url and in my GetPay View can I use Orchard.Blogs view as a partial view ?


Solution

  • In theory you can just use any view you like. However, many views require a view model. For instance, views returned by action methods probably have a view model. If you want to reuse that view, you will have to also provide an instance of that model.

    Other views are used by shapes being rendered. If you want to render those views, you will have to actually create an instance of that shape. And if those views expect certain properties to exist on the shape, you will have to set those properties as well.

    As you can probably see, this is not very straightforward, as it might potentially involve duplicating a lot of logic to build up the required data (think content part drivers that create shapes, for example).

    What I would do instead, is let us know what particular views of the Blogs module you are looking to "reuse". Perhaps there are better ways. For example, there is a BlogArchives widget you might want to use. Or maybe a Projection Widget to render all posts of a particular Blog.

    Depending on your exact use case scenario, there is bound to be a proper solution. Blindly reusing views from other modules is not typically done, because of the reasons I just listed.