Problem adding jQuery and javascript

Topics: Troubleshooting, Writing modules
Feb 8, 2012 at 6:37 PM

Hi!,

I got some problem when i want to add a reference to an script to my view. I got exception saying:The name 'Script' does not exist in the current context.

What is the proper way to add a scipt to a partial view?

Here is my view.

@model Module.Models.

ModelTest

  
 

 

@{

Script.Require("jQueryUI_DatePicker"

);

Script.Include("hint.js"

).AtFoot();

 

 

 
 

 

 

Script.Require("jQueryUI_DatePicker"

).AtFoot();

 

 

  

}

 

<div>

 

  
 

 

<label>

<span>Name:</span>

@Html.EditorFor(model => model.Namn )

</label>

<label>

<span>Date:</span>

@Html.EditorFor(model => model.Date)

</label>

</div>

Coordinator
Feb 8, 2012 at 6:41 PM

 The problem is not in the code you posted, it's in the way you are making this view render.

Feb 8, 2012 at 7:37 PM

what do u mean?, i got the error both in Visual Studio and in my browser

Coordinator
Feb 8, 2012 at 8:31 PM

The Script property is only going to be there if the template is instantiated the right way. So the problem is not in the code in the template, it's in the code that attempts to render that template. Technically, what happens is that you have the wrong base class for the view.

Feb 9, 2012 at 12:56 AM

If it's not there in VS, it could be you're using a non-standard web.config in the theme/module where the view resides, or even Orchard.Web itself. Did you use code generation to create your module/theme?

Feb 9, 2012 at 8:15 PM

hi, thx for the reply!

I have created my module with just adding a new empty MVC application in VS 2010 then just added the Module.txt file and clean up the web.config. Can this be the prblem betrandlery describs with that i ahve the wrong base class for the view?. 

Randompete i got the error message in VS 2010 aswell as in my browser runing the module.

I will try recreate the module through the code generation and se if it works better. thx again for the input!

 

 

Feb 9, 2012 at 8:55 PM

I got one follow up question about the codegenerator, when i create new modules with the code generation the projext always becomes windows application projects and not MVC project or even webporjects. Can someone explain that to me?. 

Coordinator
Feb 9, 2012 at 9:30 PM

So that Visual Studio doesn't refuse to load the solution if you don't have MVC tooling installed.