3

I am not sure if Areas are part of VS11 or MVC4, but it seems very good for organizing a big project. But I have troubles linking to Controllers in Areas.

Edit: This works now and code is updated

There is a screenshot of my project here http://www.gratisimage.dk/graphic/images/2011/October/30/724D_4EAD44CD.jpg

I have 2 links

@Html.ActionLink("Create Vehicle", "CreateVehicle", "Vehicle", new { area = "Units" }, null)
@Html.ActionLink("Index", "Index", "Vehicle", new { area = "Units" }, null)

And my Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace unoeurotest.Areas.Units.Controllers
{
    public class VehicleController : Controller
    {

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult CreateVehicle()
        {
            return View();
        }

    }
}
James McNellis
  • 348,265
  • 75
  • 913
  • 977
Mech0z
  • 3,627
  • 6
  • 49
  • 85

1 Answers1

1

In the anonymous object, specify the area.

@Html.ActionLink("Create Vessel", "CreateVessel", "Vehicle", new { Area = "Units" })
Brad Christie
  • 100,477
  • 16
  • 156
  • 200
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
  • @Html.ActionLink("Create Vessel", "Index", "Vehicle", new { area = "Units" }, null) works not sure why my Create Vessel dont work, but I will look into that – Mech0z Oct 30 '11 at 13:04
  • See this [link](http://stackoverflow.com/questions/2036305/how-to-specify-an-area-name-in-an-action-link) which says you need the new {} or null at the end. Also older [documentation](http://msdn.microsoft.com/en-us/library/ee671793(v=VS.100).aspx) which talks about areas and shows how to create ActionLinks. This still applies to MVC4. – Jon P Smith Apr 15 '13 at 09:53
  • This does not work in MVC4; you need to add a `null` argument at the end in order to use the correct overload. – Richard Ev Aug 20 '13 at 16:55