区域内的行动

时间:2011-01-18 17:00:06

标签: asp.net-mvc-2

我在区域内有一个母版页,在区域外有一个控制器。控制器名为“SecurityController”,我正在调用<%= Url.Action(“LogOut”,“Security”,new {area =“”})%>正如我在一些帖子中看到的那样,但这并没有映射到我的“根”控制器。 为/ AREANAME / SecurityController / witch的错误生成链接。

我做错了什么?

感谢大家。

1 个答案:

答案 0 :(得分:1)

我无法重现您描述的行为。以下是我所做的步骤:

  1. 使用默认模板
  2. 创建新的ASP.NET MVC 2项目
  3. 使用Visual Studio向导
  4. 添加名为AREANAME的新区域
  5. ~/Areas/AREANAME/Controller/FooController.cs

    中添加FooController
    public class FooController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    }
    
  6. 将主页从~/Views/Shared/Site.Master复制粘贴到~/Areas/AREANAME/Views/Shared/Site.Master
  7. 使用母版页添加与Index的{​​{1}}操作相对应的新Index视图。保留默认值。
  8. 在该区域的母版页内的某处添加以下内容(或在FooController的Index视图中,它并不重要):

    FooController
  9. 运行网站并导航至<%= Url.Action("Index", "Home", new { area = "" }) %>
  10. 生成了正确的网址:/AREANAME/foo/index
  11. 如果删除帮助程序的/部分,则会生成以下网址:area=""

    因此?