Changing scripts folder in MVC application and using Telerik MVC Extensions

一世执手 提交于 2019-12-11 04:22:36

问题


I am using the Telerik MVC Extensions and have moved my Scripts folder in to the Content folder. So instead of ...

    <script src="<%= Url.Content("~/Scripts/jquery-1.4.1.min.js") %>" type="text/javascript"></script>

... I now have ...

<script src="<%= Url.Content("~/Content/Scripts/jquery-1.4.1.min.js") %>" type="text/javascript"></script>

I realise that I can turn off jQuery inclusion with the ScriptRegistrar().jQuery(false) method, but how to I tell the Telerik MVC Extensions where the new "base" folder is?


回答1:


You cannot set a base folder through the API, you either follow the MVC convention or you insert your scripts manually. You can, of course, edit the code of the extensions and modify the places where the ScriptRegistrar looks for them, in the WebAssetDefaultSettings class.

That said, do you really need the scripts in the Content folder?




回答2:


I'm not sure what version of the Telerik MVC extensions it came with, but you can call DefaultPath() on the default group to change the base directory:

<%= Html.Telerik().ScriptRegistrar()
        .DefaultGroup(g => g.DefaultPath("~/Content/Scripts")
        .Add("Main.js"))
%>



回答3:


Since the code formatting is, well not there in the comments, here is my code ...

public class MvcApplication : System.Web.HttpApplication, IContainerAccessor
{

    ...

    protected void Application_Start()
    {
        ...

        WebAssetDefaultSettings.ScriptFilesPath = "~/Content/Scripts";
    }


    ...
}


来源:https://stackoverflow.com/questions/3387109/changing-scripts-folder-in-mvc-application-and-using-telerik-mvc-extensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!