0

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?

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
Serge
  • 6,554
  • 5
  • 30
  • 56
  • 1
    Why are you putting content under your `Views` folder? – Yuck Nov 06 '13 at 13:08
  • 2
    More to the point, why don't you put these in your content folder? – Paul Zahra Nov 06 '13 at 13:09
  • Those are very specific to a view. I want to keeps 1 to 1 related files in the same location. – Serge Nov 06 '13 at 13:14
  • So if you end up with multiple 1 - 1 files your views folder could quickly become unwieldy? I see what you are doing, but why still escapes me... Why not call them the view name and put them in the content folder? Or recreate the view folder structure in the content folder? – Paul Zahra Nov 06 '13 at 14:40
  • Most of the time the view name is "Index". It's just the controller name that usually changes. Then, for me DRY apply not only to code but to every element (folder's name for instance). – Serge Nov 06 '13 at 14:42

1 Answers1

3

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" />
Serge
  • 6,554
  • 5
  • 30
  • 56