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 6140507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:07:35+00:00 2026-05-23T18:07:35+00:00

When Urls are autogenerated using the Url.Action helper, if a page contains a line

  • 0

When Urls are autogenerated using the Url.Action helper, if a page contains a line similar to

@Url.Action(“Edit”,”Student”)

is expected to generate a url like domain/student/edit and its working as expected.
But if the requested url contains some parameters, like domain/student/edit/210, the above code uses these parameters from the previous request and generates something similar even though I’ve not provided any such parameter to the Action method.

In short, if the requested url contains any parameters, any auto generated links of the page (served for that request) will include those parameters as well no matter if I specify them or not in the Url.Action method.

What’s going wrong?

  • 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-23T18:07:36+00:00Added an answer on May 23, 2026 at 6:07 pm

    Weird, can’t seem to reproduce the problem:

    public class HomeController : Controller
    {
        public ActionResult Index(string id)
        {
            return View();
        }
    
        public ActionResult About(string id)
        {
            return View();
        }
    }
    

    and inside Index.cshtml:

    @Url.Action("About", "Home")
    

    Now when I request /home/index/123 the url helper generates /home/about as expected. No ghost parameters. So how does your scenario differs?


    UPDATE:

    Now that you have clarified your scenario it seems that you have the following:

    public class HomeController : Controller
    {
        public ActionResult Index(string id)
        {
            return View();
        }
    }
    

    and inside Index.cshtml you are trying to use:

    @Url.Action("Index", "Home")
    

    If you request /home/index/123 this generates /home/index/123 instead of the expected /home/index (or simply / taken into account default values).

    This behavior is by design. If you want to change it you will have to write your own helper which ignores the current route data. Here’s how it might look:

    @UrlHelper.GenerateUrl(
        "Default", 
        "index", 
        "home", 
        null, 
        Url.RouteCollection, 
        // That's the important part and it is where we kill the current RouteData
        new RequestContext(Html.ViewContext.HttpContext, new RouteData()), 
        false
    )
    

    This will generate the proper url you were expecting. Of course this is ugly. I would recommend you encapsulating it into a reusable helper.

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

Sidebar

Related Questions

My URLs look like /pages.php?page=pageName because I am using a database to supply the
I have a table that contains thousands of URLs. Each URL will have a
Urls are already conveniently in a text file, one line per url, so it's
I need urls like /controller/verb/noun/id and my action methods would be verb+noun. For example
I have textview which contains urls like www.google.com . for this textview a have
My urls for posts in WordPress looks like this: http://localhost:8888/blabla/book/yes-vi-testar Using the_permalink() would generate
urls.py url(r'^some/page/$', views.some_page, {'template_name': 'some/page.html'}, name='some_page'), views.py url = request.build_absolute_uri(reverse('some_page')).lower() response = HttpResponseRedirect(url) return
Given URLs like: http://online.wsj.com/ http://online.wsj.com/article/SB10001424052970204409004577158764211274708.html http://www.techcrunch.com/2012/01/13/techcrunch-coo/ Using Ruby/Rails, how can I return back just
The URLs like below are supported on my site: (1) http://mysite.example.com/section/ - main page
I have implemented clean URLs using the following in my .htaccess RewriteEngine on RewriteCond

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.