Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mvc action link redirect to folder within view folder

I have the following folder structure

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

how do I navigate from index.cshtml to Report.cshtml using a @html.ActionLink helper

I have tried

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

with fail.

like image 977
Wesley Skeen Avatar asked Mar 24 '23 06:03

Wesley Skeen


1 Answers

I'm still not quite sure what your setup is, but for the general case of linking to a view that is included in a subfolder of the Views folder.

Link to your controller action that handles the view, not the view itself

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

First parameter is just the link text, followed by the action, then the controller (not the view), no route parameters, and your HTML attributes.

The Report action on the Reports controller is going to look for a Views/Reports/Report.cshtml file. Since this does not exist, you can pass in a string parameter to the View() method to specify which view you're actually using.

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

  return View("PhoneCalls/Report");
}
like image 176
Brandon Avatar answered Apr 25 '23 09:04

Brandon