Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to properly reference this file?
Message
Information générale
Forum:
ASP.NET
Catégorie:
MVC
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01569507
Message ID:
01569583
Vues:
44
This message has been marked as a message which has helped to the initial question of the thread.
J'aime (1)
~ only works inside of ASP.NET parsed pages - (ie. .cshtml pages for MVC views). It doesn't work for .js files. So, if the value is dynamic you need to pass it into the script somehow.

A common pattern for this is to declare a variable in the hosting page and then pass the value in:

in the .cshtml do:
< script>
page = {
    addImagePath: "~/Content/Themes/Flexigrid/Images/add.png",
    ... other server generated vars
}
</ script>
< script src="client.js"></ script>
Note that the order is important: The script block with the ~ must preceed the client script loading so that it's visible within there when that code fires and runs.

Then in your client.js page you can reference the image with page.addImagePath:
buttons: [
    { name: 'Add', bclass: 'add', bimage: page.addImagePath,  tooltip: 'Add new client', onpress: add },
    ...
]
+++ Rick ---

>Hi everybody,
>
>In my Web application I have the following structure:
>
>Content
>      Themes
>           FlexiGrid
>                Images
>                      add.png
>
>
>And I have also
>
> Scripts
> Clients.js
>
>So, I have the following code that defines my grid in the Clients.js file
>
>
>buttons: [
>    { name: 'Add', bclass: 'add', bimage: '~/Images/add.png',  tooltip: 'Add new client', onpress: add },
>    { name: 'Edit', bclass: 'edit', tooltip: 'Edit selected client', onpress: edit },
>    { name: 'Delete', bclass: 'delete', tooltip: 'Delete selected client', onpress: del },
>    { separator: true }
>    ],
>
>This doesn't work. I am wondering how should I correctly reference the add.png for bimage ?
>
>In the flexigrid.js I see the following code:
>
>
>var btn = p.buttons[i];
>				if (!btn.separator) {
>					var btnDiv = document.createElement('div');
>					btnDiv.className = 'fbutton';
>					btnDiv.innerHTML = ("<div><span>") + (btn.hidename ? " " : btn.name) + ("</span></div>");
>					if (btn.bclass) $('span', btnDiv).addClass(btn.bclass).css({
>						paddingLeft: 20
>					});
>					if (btn.bimage) // if bimage defined, use its string as an image url for this buttons style (RS)
>						$('span',btnDiv).css( 'background', 'url('+btn.bimage+') no-repeat center left' );
>						$('span',btnDiv).css( 'paddingLeft', 20 );
>
>					if (btn.tooltip) // add title if exists (RS)
>						$('span',btnDiv)[0].title = btn.tooltip;
>
>					btnDiv.onpress = btn.onpress;
>					btnDiv.name = btn.name;
>
>
>Thanks a lot in advance.
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform