Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4539546
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:57:40+00:00 2026-05-21T14:57:40+00:00

I’m working on an ASP.NET MVC 3 app and it works fine when using

  • 0

I’m working on an ASP.NET MVC 3 app and it works fine when using the default routes. So I have urls similar to this, localhost:4457/Users/Details/5
I want to add a friendly slug to the url to make it localhost:4457/Users/Details/5/some-ones-name.
So I added a custom route and my routes now look like so

routes.MapRoute(
     "withslug",
     "{controller}/{action}/{id}/{slug}",
      new { controller = "Home", action = "Index", id = UrlParameter.Optional, slug = UrlParameter.Optional });

 routes.MapRoute(
     "Default",
     "{controller}/{action}/{id}",
      new { controller = "Home", action = "Index", id = UrlParameter.Optional });

On the view I have an action link like this

@Html.ActionLink(Model.Name,"Details","Users", new { id=Model.ID, slug="some-ones-name"},null)

I also have image links like this

<img src="../../Content/images/picture.jpg" alt="" height="42" width="37" />

The link works okay and when I click it follows correctly. The address reads localhost:4457/Users/Details/5/some-ones-name. The problem is all the images on the page are now broken and my javascript functions won’t run.
If I remove the slug from the address and just leave the url as localhost:4457/Users/Details/5 everything works as expected.

If I add even a slash after the id, everything breaks again. The content loads as expected though, just the images and some javascript functions.

I don’t understand what the problem is and any insight will be highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:57:41+00:00Added an answer on May 21, 2026 at 2:57 pm

    The slug is being treated as a directory. You would need to add an extra ../ to the image path for it to work when the url contains a slug. You should really avoid using relative paths like that on your website.

    How to fix it so that it works on every page

    You could change it to use a path that is relative to the site root like so:

    <img src="/Content/images/picture.jpg" alt="" height="42" width="37" />
    

    Or you could use a helper method that is available with asp.net mvc, it works like this. This method will auto-magically translate the path relative to the current url.

    <img src="@Url.Content("~/Content/images/picture.jpg")" ... />
    

    This will work with <script> and <link> tags as well as any other tag which references a url.

    NOTE: I am using Razor syntax above, if you are using the web forms view engine the code would look like this.

    <img src="<%: Url.Content("~/Content/images/picture.jpg") %>" ... />
    

    Additional note, I feel dirty having just written the <% %> tags after having used razor for a few months.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.