@Html.ActionLink("Engine Products", null, "Engin" />
@Html.ActionLink("Engine Products", null, "Engin" />
@Html.ActionLink("Engine Products", null, "Engin"/>
DEVHIDE
  • Home (current)
  • About
  • Contact
  • Cookie
  • Home (current)
  • About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy
  • TOS
Login Or Sign up

Html.ActionLink Action Straggler

304 Views Asked by Andrew Walters At 11 September 2013 at 00:58 2025-12-19T00:11:40.920099

I have a nav menu with links structured like so:

<div class="childLinkGroup">
    <div class="headerLink">@Html.ActionLink("Engine Products", null, "EngineProducts", null, null)</div>
    <ul>
        <li>@Html.ActionLink("Perkins Engines", "PerkinsEngines", "EngineProducts", null, null)</li>
        <li>@Html.ActionLink("Isuzu Engines", "IsuzuEngines", "EngineProducts", null, null)</li>
        <li>@Html.ActionLink("FPT PowerTrain", "FPTPowerTrain", "EngineProducts", null, null)</li>
        <li>@Html.ActionLink("Mitsubishi Engines", "MitsubishiEngines", "EngineProducts", null, null)</li>
    </ul>
</div>

And in the controller class:

// GET: /EngineProducts/
public ActionResult Index()
{
    return View(ModelData);
}

//
// GET: /EngineProducts/PerkinsEngines
public ActionResult PerkinsEngines()
{
    ModelData.MenuCategories.Where(x => x.Action == "PerkinsEngines").FirstOrDefault().Active = true;

    return View("Perkins Engines", ModelData);
}

These all work fine when accessed from the homepage.

If you're already on a child page like /EngineProducts/IsuzuEngines and try to access a different parent level link like /TransmissionProducts the IsuzuEngines is left on the link resulting in a page that can't be found.

Desired url: /TransmissionProducts

Actual url: /TransmissionProducts/IsuzuEngines

There's a bunch of overrides for Html.ActionLink and while I looked though them I don't see a different set of params that looks better.

asp.net-mvc-4 html.actionlink
Original Q&A
1

There are 1 best solutions below

2
asymptoticFault asymptoticFault On 11 September 2013 at 02:02 BEST ANSWER

When your parent links are constructed like this:

@Html.ActionLink("Engine Products", null, "EngineProducts", null, null)

The previous request value for action will be used because you are providing null when constructing the link. You should explicitly specify the action that will be used when a request is made for a parent link.

Related Questions in ASP.NET-MVC-4

  • SignalR client is not connecting to the hub after changing the client app's cookie name
  • How I Can send question and answer by without reload web page
  • Load SQL database saved MS word document to Syncfusion Document Editor
  • @Html.ValidationSummary(true) throw CSP error
  • Rotativa PDF export taking significantly longer on Windows Server 2016 after recent update
  • Two ASP.NET MVC applications overwrite same session cookie
  • List is not binding in controller, when pass it through hidden field from view in ASP.NET MVC
  • Calling AJAX methods in parallel increases server response time?
  • OpenCover Profiler Error : ProfilerCommunication::RequestInformation(...) => Communication (Chat channel - TrackAssembly) with host has failed
  • Nested child sub menus not getting generated in Asp.Net Core MVC project
  • How to show Documents on viewer when htmlmode: true in Configuration.yml file in Group Docs
  • ASP.NET MVC role is trying to use SQL Server Express not the SQL Server
  • Error HRESULT E_FAIL has been returned from a call to a COM component in Asp.net MVC
  • How I can get total number from Database by SignalR
  • Application Insights telemetry shows 'NA' from MVC 4 application behind private load balancer

Related Questions in HTML.ACTIONLINK

  • Convert Dictionary to String in MVC Razor View for HTML.ActionLink
  • My Html.ActionLink doesn't work using ASP.NET MVC 5
  • Adding Area atribute to the Html.ActionLink Does NOT Work
  • Html.ActionLink sometimes doesn't redirect to the expected path
  • MVC ActionLink Error: Cannot convert from int to string
  • How to create a string for @Html.ActionLink that concatenates an integer from the Model and a string
  • Anchor tag contains font not displayed properly if converted in @Html.ActionLink
  • Pass a string from HTML Actionlink to Controller for next View
  • How to make Html.Action parameters dynamic?
  • How to action link a route with several folders, not only controller and action?
  • passing parameter through @Html.ActionLink in asp.net core mvc
  • using template page menu links design for mvc pages
  • I want to delete a row in my database with the @Html.ActionLink Delete but its not working. What am I doing wrong?
  • C# Custom Map Routes / View Paths / Link Generation
  • How can I get an HTML tag’s value to send an HTML.Action()

Trending Questions

  • UIImageView Frame Doesn't Reflect Constraints
  • Is it possible to use adb commands to click on a view by finding its ID?
  • How to create a new web character symbol recognizable by html/javascript?
  • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
  • Heap Gives Page Fault
  • Connect ffmpeg to Visual Studio 2008
  • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
  • How to avoid default initialization of objects in std::vector?
  • second argument of the command line arguments in a format other than char** argv or char* argv[]
  • How to improve efficiency of algorithm which generates next lexicographic permutation?
  • Navigating to the another actvity app getting crash in android
  • How to read the particular message format in android and store in sqlite database?
  • Resetting inventory status after order is cancelled
  • Efficiently compute powers of X in SSE/AVX
  • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

Popular # Hahtags

javascript python java c# php android html jquery c++ css ios sql mysql r reactjs node.js arrays c asp.net json

Popular Questions

  • How do I undo the most recent local commits in Git?
  • How can I remove a specific item from an array in JavaScript?
  • How do I delete a Git branch locally and remotely?
  • Find all files containing a specific text (string) on Linux?
  • How do I revert a Git repository to a previous commit?
  • How do I create an HTML button that acts like a link?
  • How do I check out a remote Git branch?
  • How do I force "git pull" to overwrite local files?
  • How do I list all files of a directory?
  • How to check whether a string contains a substring in JavaScript?
  • How do I redirect to another webpage?
  • How can I iterate over rows in a Pandas DataFrame?
  • How do I convert a String to an int in Java?
  • Does Python have a string 'contains' substring method?
  • How do I check if a string contains a specific word?

Copyright © 2021 Jogjafile Inc.

  • Disclaimer
  • Privacy
  • TOS
  • Homegardensmart
  • Pricesm.com
  • Aftereffectstemplates