0

MVC アプリケーション フォルダー内に Index.js と Index.css ファイルを配置しましたViews/MemberField
Copy always両方のファイルに設定されています。

私はそれらをロードしようとしました:

<link href="@Url.Content("~/Views/MemberField/Index.css")" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="@Url.Content("~/Views/MemberField/Index.js")">

次の html 出力が得られます。

<link href="/Views/MemberField/Index.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/Views/MemberField/Index.js"></script>

ここまでは順調ですね。

しかし、2 つのファイルにはアクセスできません。

The resource cannot be found.

何らかのルーティング メカニズムが原因だと思うので、RouteConfig.cs ファイルを少し改ざんしました。

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.RouteExistingFiles = false;

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

        routes.IgnoreRoute("{file}.css");
        routes.IgnoreRoute("{file}.js");

        routes.MapRoute(
            name: "Default"
            , url: "{culture}/{controller}/{action}/{id}"
            , defaults: new { culture = UrlParameter.Optional, controller = "GlobalSettings", action = "Index", id = UrlParameter.Optional }
            , namespaces: new[] { "MygLogWeb" }
        );
    }
}

しかし、それは何も変わりませんでした。

どうしたの?

4

1 に答える 1

3

わかりました、修正しました。

私は間違った方向を見ていました。
Visual Studio は、次の行を持つ Views フォルダーに web.config ファイルを作成します。

<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />

私はちょうど変更しなければならなかった

<add name="BlockViewHandler" path="*.cshtml" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
于 2013-11-06T13:32:24.107 に答える