2011-06-09 40 views
0

MVC3路線與JS路徑干擾,我有以下途徑定義

routes.MapRoute(name: "StateResults", url: "{state}/{searchTerm}", defaults: new { controller = "Results", action = "SearchState" }); 

在我的共享CHTML文件中的一個,我有以下定義:

<script src="@Url.Content("Scripts/jquery-1.5.1.js")" type="text/javascript"></script> 

我理解爲什麼JS是不是得到加載,但我怎麼解決這個問題?我解決了這個問題?

謝謝。

回答

1

您可以ignore routes for JS

IgnoreRoute("{file}.js"); 

作爲一種替代方法,你可以使用約束參數R鍵避免文件與js

routes.MapRoute("StateResults", "{state}/{searchTerm}", 
    new { controller = "Results", action = "SearchState" }, 
    new { searchTerm = @".*?([^js])$" }); // regex not tested 

RouteCollectionExtensions.MapRoute Method (RouteCollection, String, String, Object, Object) from MSDN

constraints 
    Type: System.Object 
    A set of expressions that specify values for the url parameter.