MVC操作链接重定向到视图文件夹中的文件夹

Wes*_*een 2 asp.net-mvc razor

我有以下文件夹结构

->People
-->Views
--->Reports
--->index.cshtml
---->PhoneCalls
----->Report.cshtml
-->Controlers
--->ReportsControler.cs
Run Code Online (Sandbox Code Playgroud)

如何使用@html.ActionLink助手从index.cshtml导航到Report.cshtml

我试过了

@Html.ActionLink("Report", "PhoneCalls/Report", null, new { target = "__blank" });
Run Code Online (Sandbox Code Playgroud)

失败了。

Bra*_*don 5

我仍然不太确定您的设置是什么,但是对于链接到文件夹子文件夹中包含的视图的一般情况而言Views。

链接到处理视图的控制器操作,而不是视图本身

@Html.ActionLink("Report", "Report", "Reports", null, new { target = "_blank" });
Run Code Online (Sandbox Code Playgroud)

第一个参数只是链接文本,然后是操作,然后是控制器(不是视图),没有路由参数和HTML属性。

在Reporton动作Reports控制器是要寻找一个Views/Reports/Report.cshtml文件。由于不存在View()此视图,因此可以将字符串参数传递给该方法以指定您实际使用的视图。

public ActionResult Report()
{
  // Do your controller work

  return View("PhoneCalls/Report");
}
Run Code Online (Sandbox Code Playgroud)