Using Style.Require

Jan 3, 2011 at 10:58 PM

I have a basic ContentPart that I want to use some jQuery on. I am trying to include jQuery in my view using this bit of code:


However, I get a generic compilation error:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS0103: The name 'Style' does not exist in the current context

Source Error:

Line 2:  
Line 3:  @{
Line 4:      Style.Require("jQuery");
Line 5:  }
Line 6: 

Jan 4, 2011 at 4:15 AM
Edited Jan 4, 2011 at 4:18 AM

Style.Require is the incorrect  syntax. For including styles use Style.Include("~/Styles/mystyle.css").

Rather use


for registering the jQuery script library.

Jan 4, 2011 at 2:25 PM

Oops. My mistake, that was just a typo. I'm actually trying to include both a style sheet and a script. Both Script and Style give me the same error. Style.Include still throws the same error (does not exist in the current context). 

I've also tried adding a ResourceManifest file like this:

    public class ResourceManifest : IResourceManifestProvider
        public void BuildManifests(ResourceManifestBuilder builder) {
            var manifest = builder.Add();


But, I'm not sure if I'm supposed to register that I have it somewhere or if it just gets picked up by Orchard. In either case, I can't use Style or Script on my view page.

Jan 4, 2011 at 5:23 PM

Is this a shape template?

Jan 4, 2011 at 7:24 PM

I think so? What's the difference between a shape and a content part? I think a content part view gets a shape, right?

I just created a module and defined a content part in it. I am trying to put this code in the view for the content part. I really used the jQuery module as a template and added a content part that I intend to use my custom script on (which depends on jQuery). 


Jan 4, 2011 at 7:27 PM

Yes, a part gets a shape. It's just that it seems like for some reason the view is not inheriting from the right base class, which means the environment is somehow not right. It would help to see some of the code, for example the driver.

Jan 4, 2011 at 7:49 PM

This is all of the code. I'm still not 100% clear on drivers and handlers, so there may be some issue there. 

/* My Content Part */
public class ArtworkUploadPart : ContentPart
	public string OrderItemTrackingNumber { get; set; }

/* The Handler */
    public class ArtworkUploadHandler : ContentHandler
        public ArtworkUploadHandler()
            OnLoaded<ArtworkUploadPart>((ctx, cp) => {
                                            cp.OrderItemTrackingNumber = Convert.ToString(HttpContext.Current.Request["trackingNumber"]);

/* The Driver */
public class ArtworkUploadDriver : ContentPartDriver<ArtworkUploadPart>
	protected override DriverResult Display(ArtworkUploadPart part, string displayType, dynamic shapeHelper) {
		return ContentShape("Home_Index", () => shapeHelper.Home_Index(part));

/* Migrations */
public int Create()
	   .AlterPartDefinition("ArtworkUploadPart", cfg => cfg

	return 1;

/* The view for the part, located here: MyModule/Views/Home/Index.cshtml */
@{ Script.Require("jQuery"); }
<h2>Artwork Upload</h2>

<input type="hidden" id="orderItemTrackingNumber" value="@Model.OrderItemTrackingNumber" />
<input id="file-upload" name="file-upload" type="file" />

Jan 4, 2011 at 8:31 PM

Ah, any reason why you're not following the convention for the shape name? Home_Index seems awfully generic and will make theming problematic.

Jan 4, 2011 at 10:57 PM

Probably because I don't know what the convention is, I thought that that was telling Orchard where the view was: "views\home\index.cshtml" then becomes "Home_Index", "views\parts\index.cshtml" becomes "Parts_Index". 

When I place a break point in the driver, it's not being hit, so I guess my driver isn't being called? 

Jan 4, 2011 at 11:01 PM

What are you requesting? You do have a content type that has this part, right?

Jan 4, 2011 at 11:38 PM

Uh oh. Things are slowly clearing. I wasn't actually at that point yet. I was just requesting the URL I set in the Routes.cs file for the module. 

I added this part to a content type, then created an item of that type. Now, when I request that item, my break points get hit. BUT, I still get the same error as in my initial post. I changed the Home_Index shape to Parts_Upload just to make sure there wasn't some conflict. If I remove the @{ Script.Require("jQuery"); }, it loads the view without any errors.


Jan 5, 2011 at 12:25 AM

You're not using that route any more are you?

Jan 5, 2011 at 12:50 AM

I am not. I created a content type that only has this content part and routable. When I create and instance, and browse to the link of that item, I still get the error. 

Jan 5, 2011 at 1:06 AM

Mmh. I don't have any other ideas now. Can you package the module and send it to me at bleroy you know where?

Jan 5, 2011 at 9:17 PM

OK, so I was able to make your code work. The problem is that you probably got that web.config in your views folder from VS tooling. The problem is that it tells Razor to use the stock MVC base class for the view instead of the Orchard one. I replaced your web.config with the one that comes from codegen and it worked.

Jan 5, 2011 at 10:14 PM

OK, that worked. I think I had to create the project outside of codegen because it wasn't adding references to MVC 3 for some reason (although I just tried again to make sure, but it added it fine). Thanks for all your help! Soon, I will start adding to that gallery!