ASP.NET MVC `Html.ActionLink` between “Areas”

后端 未结 6 542
灰色年华
灰色年华 2021-01-31 01:58

I have added a new Area to my MVC3 project and I am trying to link from the _Layout page to the new Area. I have added an Area called \'Admin\' that has a controller \'Meets\'.<

6条回答
  •  温柔的废话
    2021-01-31 02:47

    Strange indeed. Steps that worked perfectly fine for me:

    1. Create a new ASP.NET MVC 3 application using the default Visual Studio template
    2. Add an area called Admin using Visual Studio designer by right clicking on the project
    3. Add new Controller in ~/Areas/Admin/Controllers/MeetsController:

      public class MeetsController : Controller
      {
          public ActionResult Index()
          {
              return View();
          }
      }
      
    4. Add a corresponding view ~/Areas/Admin/Views/Meets/Index.cshtml

    5. In the layout (~/Views/Shared/_Layout.cshtml) add links:

      @Html.ActionLink("Admin", "Index", "Meets", new { area = "Admin" }, null)
      @Html.ActionLink("Admin", "Index", "Meets", new { area = "" }, null)
      
    6. Run the application.

    Rendered HTML for the anchors:

    Admin
    Admin
    

    As expected the first link works whereas the second doesn't.

    So what's the difference with your setup?

提交回复
热议问题