0

I save menu links in my database with the format: "master/country", master is area name, and country is controller name. My web URL is http://localhost/appname. When I click the country menu, its redirects to the country page (http://localhost/appname/master/country). But when I click again the City menu item (in master area too), it redirects to http://localhost/appname/master/master/city. I write menu links in a StringBuilder (including a tag) and store it in viewbag.

I tried changing menu links to "/master/country", then the URL becomes http://localhost/master/country when I click first menu (country).

I am using MVC 5. How to create a links menu within the same area?

Dale K
  • 25,246
  • 15
  • 42
  • 71
Blishton
  • 109
  • 2
  • 9

2 Answers2

1

This will help access an area from an action link

@Html.ActionLink("MyText", "ActionName", "ControllerName", new { area = "YourAreaName"}, null)

This will help you more options on SO

Or you create an area specified with controllers using above link

Html.ActionLink("Link Text", "ActionName", "ControllerName", new { Area = "AreaName" }, new{})
Transformer
  • 6,963
  • 2
  • 26
  • 52
  • I create method at different Project. I think Html.ActionLink and Html.ActionLink must be in System.Web.Mvc.Controller class. How to call HtmlActionLink in different project ? – Blishton Aug 31 '21 at 06:53
0

You can try this in action method

 return RedirectToAction("ActionName", "ControllerName", new { area = "AreaName" });