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?

5
  • 1
    Why are you putting content under your Views folder? Commented Nov 6, 2013 at 13:08
  • 2
    More to the point, why don't you put these in your content folder? Commented Nov 6, 2013 at 13:09
  • Those are very specific to a view. I want to keeps 1 to 1 related files in the same location. Commented Nov 6, 2013 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? Commented Nov 6, 2013 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). Commented Nov 6, 2013 at 14:42

1 Answer 1

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" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.