【问题标题】:How to link to areas in MVC4如何链接到 MVC4 中的区域
【发布时间】:2011-12-18 04:47:23
【问题描述】:

我不确定 Areas 是 VS11 还是 MVC4 的一部分,但它似乎非常适合组织大型项目。但是我在连接到区域中的控制器时遇到了麻烦。

编辑:现在可以使用并且代码已更新

这里有我的项目截图http://www.gratisimage.dk/graphic/images/2011/October/30/724D_4EAD44CD.jpg

我有 2 个链接

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

还有我的控制器

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();
        }

    }
}

【问题讨论】:

    标签: visual-studio asp.net-mvc-4


    【解决方案1】:

    在匿名对象中,指定区域。

    @Html.ActionLink("Create Vessel", "CreateVessel", "Vehicle", new { Area = "Units" })
    

    【讨论】:

    • @Html.ActionLink("Create Vessel", "Index", "Vehicle", new { area = "Units" }, null) 不知道为什么我的 Create Vessel 不起作用,但我会调查一下
    • 看到这个link,它说你需要新的 {} 或最后的 null。还有较早的documentation,它讨论了区域并展示了如何创建 ActionLinks。这仍然适用于 MVC4。
    • 这在 MVC4 中不起作用;您需要在末尾添加 null 参数才能使用正确的重载。
    猜你喜欢
    • 2018-11-27
    • 1970-01-01
    • 2020-07-20
    • 1970-01-01
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多