4

次のフォルダー構造があります

->People
-->Views
--->Reports
--->index.cshtml
---->PhoneCalls
----->Report.cshtml
-->Controlers
--->ReportsControler.cs

@html.ActionLinkヘルパーを使用して index.cshtml から Report.cshtml に移動する方法

私が試してみました

@Html.ActionLink("Report", "PhoneCalls/Report", null, new { target = "__blank" });

失敗します。

4

1 に答える 1

7

セットアップが何であるかはまだよくわかりませんが、フォルダーのサブフォルダーに含まれるビューにリンクする一般的な場合ですViews

ビュー自体ではなく、ビューを処理するコントローラー アクションへのリンク

@Html.ActionLink("Report", "Report", "Reports", null, new { target = "_blank" });

最初のパラメーターは単なるリンク テキストで、その後にアクション、次にコントローラー (ビューではない)、ルート パラメーターはなく、HTML 属性が続きます。

コントローラーのReportアクションはReports、ファイルを探しViews/Reports/Report.cshtmlます。これは存在しないため、文字列パラメーターをView()メソッドに渡して、実際に使用しているビューを指定できます。

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

  return View("PhoneCalls/Report");
}
于 2013-07-05T15:42:28.043 に答える