Putting data into views

Topics: Customizing Orchard, General
May 13, 2013 at 4:48 PM
This may be more of an MVC question, but I'm using Orchard in my implementation so I figured I would put it here.

I am using a service class to query the orchard DB. Then, I'm writing out my HTML as a string in a method marked with the [Shape] attribute. The problem is, it gets tricky to maintain and looks bad. I'd prefer instead to push my data to a razor and assemble my view there, but I can't figure out how.

Basically, I'd prefer to put forth my html as a cshtml file as opposed to a very long string. Thanks in advance for any advice on this. If you need more information or code to help assist me I will be happy to share.
Developer
May 13, 2013 at 5:27 PM
Could you explain what's stopping you from using a .cshtml file as the view?
May 13, 2013 at 5:51 PM
Currently I am, but I'm having trouble getting my data from the server to the razor. My widget is querying 4 lists using the projector and I grab data from the content items that are found, process it, and now I want to send the collection of the data I found (for instance in a view model) to a razor file. Right now it's using the razor I put into the views folder, but it's only displaying plain old html. I can't figure out how to put data objects in there for it to use.
Developer
May 13, 2013 at 6:18 PM
When you say that your widget is quering 4 lists using the projector, from where are you doing that: the driver? If so, then that's the place where you setup your shapes to be rendered. Those shapes will map to views and will be the model of those views. You can stick any data you need for your view into a shape.
May 13, 2013 at 6:32 PM
Edited May 13, 2013 at 6:39 PM
Ah, I was unaware you could do that. How would I set up the projector to query from within a driver class?

edit- I'll also add that I'm using a resource you wrote here: http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-part-5

I'm wondering if I can use this, but the content items on my lists are the OOB page content type, and I don't want to muck around too much with how those are displaying. Instead I'd rather just process the data myself and create my own view. Unless you think that would be best?