2015-04-29 29 views
0

我通過NuGet爲MVC 5安裝了RouteJS,並遵循安裝說明,但嘗試加載<script src='/routejs.axd/251810a87f19ffe842a619acc9a90d73349ba4fa/router.js'></script>時返回_Layout.cshtml的內容和狀態200。C#MVC 5,RouteJs返回HTML而不是JS

我正在運行MVC 5,C#和IIS Express 8.我嘗試了一下我在其GitHub/NuGet網站上找到的Web.config的新變體。如果我使用區域,是否需要額外的配置?

#_Layout.cshtml 
#This works 
<script src="@RouteJs.RouteJsHandler.HandlerUrl"></script> 

#Web.config 
<configSections> 
    <section name="routeJs" type="RouteJs.RouteJsConfigurationSection, RouteJs" /> 
</configSections> 

#This section by itself will break the application. 
#Added the 'validation' line to system.webServer to prevent an error 
#I've tried running RouteJS with and without this section. 
<system.web> 
    <httpHandlers> 
     <add verb="GET" path="routejs.axd" type="RouteJs.RouteJsHandler, RouteJs" /> 
    </httpHandlers> 
</system.web> 

<system.webServer> 
    <handlers> 
     <validation validateIntegratedModeConfiguration="false"/> 
     <add name="RouteJs" verb="GET" path="routejs.axd" type="RouteJs.RouteJsHandler, RouteJs" /> 
    </handlers> 
</system.webServer> 

<routeJs exposeAllRoutes="true" /> 

#RegisterRoutes 
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

回答

0

您必須聲明這樣的的地區代碼,以添加路由:

public class AdminAreaRegistration : AreaRegistration 
    { 
     public override string AreaName 
     { 
      get 
      { 
       return "Admin"; 
      } 
     } 

     public override void RegisterArea(AreaRegistrationContext context) 
     { 
      context.MapRoute(
       "Admin_default", 
       "Admin/{controller}/{action}/{id}", 
       new { action = "Index", id = UrlParameter.Optional } 
      ); 
     } 
    } 
+0

我對MVC的區域設置。我不知道RouteJS是否需要其他配置,因爲我正在使用區域。 – Josh

+0

你可以嘗試使用沒有區域的routejs嗎? – clement

+0

RouteJS在創建沒有區域的默認MVC應用程序時工作。我將繼續使用這個應用程序,看看它什麼時候中斷。 – Josh