0

I'm having this strange routing problem - I have 2 kinds of routes to the same view. Such as Simulator/RunStrategy/7 and Simulator/RunStrategy/7/1000.

Where as the controller and view is defined as public ActionResult RunStrategy(int id, decimal sum).

When I use the short one I see the view as needed, when i use the long one - I get all the "link href...." messed up. Such as:

<link href="../../../css/global.css" rel="stylesheet" type="text/css" />

Where it should be:

<link href="../../css/global.css" rel="stylesheet" type="text/css" />

Which really is displayed correctly when I use the short routing link.

The routing table is as follows:

        routes.MapRoute(
            "Run Simulation",
            "Simulator/RunStrategy/{id}/{startingsum}",
            new { controller = "Simulator", action = "RunStrategy", id = "0", startingsum = "100000" },
            new { id = @"\d+", startingsum = @"^([0-9]*|\d*\.\d{1}?\d*)$" }
        );

Where it works fine.

Help would be much appreciated. Thanks.

4
  • How are linking your CSS files? Are you using Url.Content()? Commented Aug 12, 2010 at 13:48
  • Should I? I'm using direct links as given above (for the short route version) and it is being added "../" at the long route for some reason. Commented Aug 12, 2010 at 13:50
  • 1
    have you thought about simply using root path, e.g. /themes/css/global.css? Commented Aug 12, 2010 at 13:54
  • for some strange reason it just doens't work. It needs those "../../" to work - where it really should accept the root path. ideas why so? Commented Aug 12, 2010 at 13:56

1 Answer 1

2

You should try using Url.Content() and see if that makes a difference.

Example:

<link href="<%=Url.Content("~/Content/Site.css")%>" rel="stylesheet" type="text/css" />
Sign up to request clarification or add additional context in comments.

8 Comments

I've tried that one - it gives me a link to "/css/global.css" where it should be "../../css/global.css"
BTW - the problem is only with CSS files. for JS it works fine.
What is the full path of your global.css file?
it's at the root of the site with /css/global.css (i.e <root>/css/global.css) - where as the directories are standard MVC dir structure.
If /css/global.css is the full path of your file, and the Url.Content() outputs <link href="/css/global.css" type="text/css" rel="stylesheet" />, then it should work from every page because it's using an absolute url instead of a relative one. Are you sure there isn't some other problem?
|

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.