@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

303 Views Asked by Andrew Walters At 11 September 2013 at 00:58 2025-12-18T10:28:51.488729

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

  • Jquery: Change contents of <select> tag dynamically
  • redirect to actionResult method from an api
  • Open another view through controller from jQuery?
  • ASP MVC 5 Html.EditorFor not working / Unable to access/use Default Editor Templates
  • Having error in updating my record in database my method as follows
  • Is it possible to access an additional custom model property from viewdata.modelmetadata.properties?
  • Which plugin is used to show the data in front end of socrata
  • Set focus on button that triggered page reload
  • jQuery: How to traverse / Iterate over a list of object
  • Switching CSS Just for that view?
  • Protractor, login to asp,net MVC login page, wait for default page then , redirect to angular page and do tests....how?
  • Ajax.beginForm() cannot get post value
  • Get desired html element's attribute value and set to hidden field before binding in Asp.Net MVC
  • Get Value From Dynamically Populated Hidden Field
  • Asp.net MVC Routelink null controller parameter

Related Questions in HTML.ACTIONLINK

  • I cant receive ActionLink Parameters in controller?
  • T4MVC: Empty link on shared view when controller is in an area
  • C# MVC 5 Html.ActionLInk
  • Adding html.actionLink to Jquery Datatable
  • @Html.ActionLink is not linking to current area by default
  • @html.actionlink renders wrong url
  • Order List in MVC 4 ASP.NET i.e. Controller receiving 2 variables
  • Sending Json data to @Html.Actionlink() in Jquery in MVC4
  • Passing id value of actionlink to javascript function in my Asp.net Mvc Project
  • C# how to set a class attribute value dynamically in an ActionLink?
  • asp .net @Html.ActionLink dynamic id (parameter)
  • How do I use an ActionLink with the RouteValueDictionary?
  • Using HTML tags inside linkText of Html.ActionLink
  • How to use CSS on an Html.ActionLink in C#
  • Html.ActionLink adding params with ? and & instead of slashes

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

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
  • Math
  • Aftereffectstemplates