Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
898 views
in Technique[技术] by (71.8m points)

asp.net mvc - how to route to css/js files in mvc.net

I am trying to add an area to my application using routing in mvc.net. For controllers i added:

routes.MapRoute(
                "Area1", // Route name
                "Area1/{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );

how can i route the css/js files in the same way, i.e. i would like to have area1/content/site.css going to /content/site.css or to /content/area1/site.css.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

like this

for /content/site.css

if you want to always goto site.css:

routes.MapRoute(
                "Area1", // Route name
                "/{action}/site.css", // URL with parameters
                new { controller = "Area1", action = "content" } // Parameter defaults
            );

and if you want to goto different css by providing css name:

routes.MapRoute(
                "Area1", // Route name
                "/{action}/{resource}.css", // URL with parameters
                new { controller = "Area1", action = "content", resource = UrlParameter.Optional } // Parameter defaults
            );

for /content/area1/site.css

routes.MapRoute(
                    "Area1", // Route name
                    "/{action}/Area1/{resource}.css", // URL with parameters
                    new { controller = "Area1", action = "content", resource = UrlParameter.Optional } // Parameter defaults
                );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...