I have put an Index.js and an Index.css file inside my MVC application folder Views/MemberField.
Copy always is set for both files.

I tried to load them using:

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

which give the following html output:

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

So far so good.

But the two files cannot be accessed.

The resource cannot be found.

I thinks it's because of some routing mechanism so I tampered a bit with my RouteConfig.cs file.

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" }
        );
    }
}

But it didn't change a thing.

What's wrong?

有帮助吗?

解决方案

Ok, fixed it.

I was looking the wrong way.
Visual Studio create a web.config file in Views folder having the following line:

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

which I just had to change to

<add name="BlockViewHandler" path="*.cshtml" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top