I have a asp.net mvc4 view which includes some partial views. This view also contains a submit button to filter some elements in the grid, see below:
Configure.cshtml
<div id="MyDiv">
@Html.Partial("../Grids/_CompGrid")
</div>
@using (Ajax.BeginForm("Search", "Component", ...)
{
<input type="submit" name="_search" value="@Resource.CaptionComponentApplyFilter" />
}
ComponentController.cs
public PartialViewResult Search()
{
// Do some stuff
return PartialView("_CompGrid");
}
When returning the partial view above indicated it crashes. It seems like it is not handling the correct path to the partial view. See below message error:
The partial view '_CompGrid' was not found or no view engine supports the searched locations.
The following locations were searched:
~/Views/Component/_CompGrid.aspx
~/Views/Component/_CompGrid.ascx
~/Views/Shared/_CompGrid.aspx
~/Views/Shared/_CompGrid.ascx
~/Views/Component/_CompGrid.cshtml
~/Views/Component/_CompGrid.vbhtml
~/Views/Shared/_CompGrid.cshtml
~/Views/Shared/_CompGrid.vbhtml
Below the directory structure overview of the above files indicated.
/root
|
|__ Controllers
| |
| |__ ComponentController.cs
|
|__ Views
| |
| |__ Home
| | |
| | |__ Configure.cshtml
| |
| |__ Grids
| | |
| | |__ _CompGrid.cshtml
| |
| |
Any ideas on how can I solve this?
SOLUTION:
Replace below return line in the function:
public PartialViewResult Search()
{
// Do some stuff
return PartialView("_CompGrid");
}
by:
return PartialView("../Grids/_CompGrid");
but anyway if someone has a better idea, it will be welcome.