Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controller can not find partial view

So I have a controller called myPartiaViewController with the path

Controllers/myPartiaViewController.cs

and I have a partial view, _mypartialView, inside a folder, myPartialView, that is inside another folder, MainView, in the Views folder

Views/MainView/myPartialView/_myPartialView.cshtml

I have a method in my controller

[HttpPost]
[ChildActionOnly]
public ActionResult myPartialView()        
    return PartialView("MainView/myPartialView/_myPartialView.cshtml", model);}
}

For some reason my controller can not resolve the partial view. what going on?

like image 543
Jack Thor Avatar asked Sep 14 '26 19:09

Jack Thor


1 Answers

Use return PartialView("~/Views/MainView/PartialView/_myPartialView.cshtml", model);

it's the ~ that does it. Otherwise you'll look for a top-level MainView folder, which is not as intended.

like image 50
Jeroen Vannevel Avatar answered Sep 16 '26 09:09

Jeroen Vannevel