Reputation: 11201
The below image shows the Partial View GetMovieTypes.cshtml
living in the Shared
folder
I call the partial view using the line @Html.Partial("GetMovieTypes.cshtml")
in the Index View of EmployeeController
Issue is I get Server Error when I call the Employee Controller with Index Action
The partial view '_GetMovieTypes.cshtml' was not found or no view engine supports the searched locations. The following locations were searched:
~/Areas/Staff/Views/Employee/GetMovieTypes.cshtml.cshtml
But when I rename the PartialView to GetMovieTypes.cshtml.cshtml
it works fine
Why is the ViewEngine forcing me to add the .cshtml extension twice
Upvotes: 1
Views: 3072
Reputation: 1200
You need to remove the .chtml extension:
@Html.Partial("GetMovieTypes")
You can also pass the model you havbe in the "parent" view like this:
@Html.Partial("GetMovieTypes", MovieTypesModel)
With this method, your view and its partial have the same model and information
*Maybe I'm wrong but I think you have an underscore in the name of the view too, so you should call it like this:
@Html.Partial("_GetMovieTypes", MovieTypesModel)
Upvotes: 2
Reputation: 75133
you should change your code call into
@Html.Partial("_GetMovieTypes")
as that's the name of your View, I do that all the time.
there is no need to mention the extension, that's only if you are calling from your Controller
.
my own example:
Upvotes: 2
Reputation: 62265
You simply need to call
@Html.Partial("GetMovieTypes")
Dot is not recognized as extension separator by MVC
binding. So if you write
"GetMovieTypes.cshtml" it searches for exactly that name, plus cshtml
extension.
Upvotes: 4