This is a migrated thread and some comments may be shown as answers.

[Solved] Using scripts assets with T4MVC

10 Answers 240 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vincent Girard
Top achievements
Rank 1
Vincent Girard asked on 02 Mar 2010, 11:09 PM
Hi,

I want to use the combined and compress of the Web assets, I added the following code in my global.cs :

SharedWebAssets.Scripts(s => s.AddGroup("master", g => g.Add(Links.Content.javascripts.functions_js) 
                                                                    .Add(Links.Content.javascripts.xVal_jquery_validate_js) 
                                                                    .Add(Links.Content.javascripts.xVal_AspNetNative_js) 
                                                                    .Add(Links.Content.javascripts.xVal_Messages_fr_FR_js) 
                                                                    .Combined(true
                                                                    .Compress(true))); 

But when I run the project i get an error because it's looking in the folder "scripts" but my scripts are in /content/javascripts/. Is there a way to change the base folder of the script registrar?

Also, if I want to use google's CDN (http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js) how can I do this?

Here's my exception :

Specified file does not exist: "~/Scripts/CFMSVente/CFMSVente/Content/javascripts/functions.js".

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Specified file does not exist: "~/Scripts/CFMSVente/CFMSVente/Content/javascripts/functions.js".


Thank you!

NB : For more information on T4MVC : http://aspnet.codeplex.com/wikipage?title=T4MVC

10 Answers, 1 is accepted

Sort by
0
Vincent Girard
Top achievements
Rank 1
answered on 03 Mar 2010, 04:06 AM
I'm also facing others problems :

-If i want to add a script to a specific view witch use my master I get the 

You cannot call render more than once. error, wich after doing some research I still don't understand how to do it right.

-I'm using xVal for my validation and if I don't put their javascript in the top of the page(head) the script is not working and I get an error

0
Alex Gyoshev
Telerik team
answered on 03 Mar 2010, 08:32 AM
Hello Vincent,

A lot of questions, so straight to the answers:
  • adding scripts using T4MVC - you should prefix them with "~" - not very pretty. If you despise how it looks, you can patch the T4 template to generate them this way.
  • linking to the Google CDN - just disable the jQuery (using jQuery(false)) and the script that you want. Please note that we also have a CDN at your disposal, if you want to use it.
  • rendering more than once - well, obviously, you can't do that. The solution is simply to not render the script registrar in the two places: add the scripts that you need in the view, without calling render, and leave the rendering to the master page.

Kind regards,
Alex Gyoshev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Vincent Girard
Top achievements
Rank 1
answered on 03 Mar 2010, 03:31 PM
Hello Alex, thx for the reply!

If I do 
SharedWebAssets.Scripts(s => s.AddGroup("master", g => g.Add("~" + Links.Content.javascripts.functions_js) 
                                                                    //.Add("/Content/javascripts/functions.js") 
                                                                    .Combined(true
                                                                    .Compress(true))); 

I get this error : 

Specified file does not exist: "~/CFMSVente/CFMSVente/Content/javascripts/functions.js".


Also, what if I don't want the CSS of the grid to rendre in all of my pages but only when I have a Grid? If I do <% Html.Telerik().StyleSheetRegistrar().StyleSheets(s => s.AddSharedGroup("styles")).Render(); %> does it render all the CSS for tyelerik control?
0
Vincent Girard
Top achievements
Rank 1
answered on 03 Mar 2010, 03:55 PM
One problem I'm facing right now :

- I'm using xVal for my validation and if I don't put their javascript in the top of the page(head) the script is not working and I get an error. If I put this in my view <% Html.Telerik().ScriptRegistrar().jQuery(false).Scripts(s => s.AddSharedGroup("xVal")); %> it render the script at the end of my HTML... is it possible to have it in the head?


0
Atanas Korchev
Telerik team
answered on 03 Mar 2010, 04:42 PM
Hello Vincent Girard,

It is not possible to include a JavaScript file in the head tag using the ScriptRegistrar. You should manually include the xVal and jQuery JavaScript files.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Vincent Girard
Top achievements
Rank 1
answered on 11 Mar 2010, 07:13 PM
I have an other question on T4MVC but with the grid this time, if I want to use it to make the call to the controller it's not working :

these 2 lines should do the same but it's not working with telerik controls, do you know why and have any plans of making it work?

.DataBinding(d => d.Ajax().Select(MVC.Admin.ListAjax()))
.DataBinding(d => d.Ajax().Select("ListAjax", "Admin"))

It gives me this error : ActionResult is not assignable to parameter type string

Thx
0
Alex Gyoshev
Telerik team
answered on 12 Mar 2010, 08:51 AM
Hello Vincent,

Please check the following blog post on using the T4MVC helpers with navigational components. The situation with the grid actions is the same - we cannot provide support for the ActionResult, since it is generated by the T4MVC template (it's actually a T4MVC_ActionResult that holds the controller/action information).

You can use the same approach and define an extension method for the GridBindingSettingsBuilder class, like this:

public static class GridBindingSettingsBuilderExtensions
{
    public static GridBindingSettingsBuilder Select(this GridBindingSettingsBuilder instance, ActionResult action)
    {
        var t4ActionResult = action as T4MVC_ActionResult;

        instance.Select(t4ActionResult.Action, t4ActionResult.Controller, t4ActionResult.RouteValues);

        return instance;
    }
}


All the best,
Alex Gyoshev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Sam Critchley
Top achievements
Rank 1
answered on 10 Nov 2010, 07:20 AM
Use this:
public static class TelerikExtensions
    {
        public static void AddT4(this WebAssetItemGroupBuilder builder, string value)
        {
            builder.Add("~" + value);
        }
    }

<% Html.Telerik().ScriptRegistrar().DefaultGroup(p => p.AddT4(Links.Scripts.wizard.screen1_js)); %>
0
Daniel
Top achievements
Rank 1
answered on 14 Nov 2010, 04:39 AM
@Sam.

I modified your code for work with the last version of Telerik.

Create WebAssetGroupBuilderExtensions.cs file class in the Extensions folder.

Put this code inside the class:

using Telerik.Web.Mvc.UI;
 
public static class WebAssetGroupBuilderExtensions
{
    public static WebAssetGroupBuilder AddT4(this WebAssetGroupBuilder instance, string value)
    {
        instance.Add("~" + value);
        return instance;
    }
}


Use with css and javascript files as show:

<%= Html.Telerik().StyleSheetRegistrar()
                      .DefaultGroup(group => group
                          .AddT4(Links.Content.telerik_examples_css)
                          .AddT4(Links.Content._2010_3_1111.telerik_common_min_css)
                          .AddT4(Links.Content._2010_3_1111.telerik_vista_min_css)
                          .Combined(true)
                          .Compress(true))
                      %>
 
 
<%= Html.Telerik().ScriptRegistrar()
                      .Globalization(true)
                      .DefaultGroup(group => group
                          .AddT4(Links.Scripts.jquery_1_4_3_min_js)
                          .AddT4(Links.Scripts.jquery_validate_min_js)
                          .AddT4(Links.Scripts.MicrosoftAjax_js)
                          .AddT4(Links.Scripts.MicrosoftMvcValidation_debug_js)
                          .Combined(true)
                          .Compress(true))
                      .jQuery(false)%>

Enjoy!

Daniel.
0
bbeatty
Top achievements
Rank 1
answered on 08 Feb 2012, 09:42 PM
this doesn't appear to be working. When I try to use the following code
@(Html.Telerik().StyleSheetRegistrar()
.DefaultGroup(group => group
           .Add(Links.Content._2011_3_1115.telerik_common_min_css)
           .Add(Links.Content._2011_3_1115.telerik_office2010silver_min_css)
           .Add(Links.Content.Site_css)
    .Combined(false)
    .Compress(true))
    )



 I get this error,


Specified file does not exist: "~/Content/MyProject/Content/2011.3.1115/telerik.common.min.css". 

 AddT4 has the similar result, but removed the first /Content directive


If I change .Combined to True. then it ignores the error, but no styles are sent to the browser
Tags
General Discussions
Asked by
Vincent Girard
Top achievements
Rank 1
Answers by
Vincent Girard
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Atanas Korchev
Telerik team
Sam Critchley
Top achievements
Rank 1
Daniel
Top achievements
Rank 1
bbeatty
Top achievements
Rank 1
Share this question
or