I'm creatig an MVC project from scratch and I can't call a controller and its view from _Layout.
I created View XMenu in folder Views/XMenu/
It has its own controller XMenuController in folder Controllers/
In _Layout, I call controller using Html.RenderAction. I also tried Html.Action but with no success.
<div>
@{ @Html.RenderAction("MenuAction", "XMenu") };
</div>
Controller XMenu
public class XMenuController : Controller
{
//
// GET: /XMenu/
public ActionResult Index()
{
return View();
}
[ChildActionOnly]
public ActionResult MenuAction()
{
return PartialView();
}
}
View XMenu:
My Menu
I haven't put any parameters yet, just trying to call a controller and its view from _Layout, but get error:
Compiler Error Message: CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments
- Is it possible to call a controller and its view from _Layout?
- How should I call it?
EDIT:
I tried @Html.Action("MenuAction", "XMenu") };
I tried renaming view to MenuAction.cshtml.
I tried @{ Html.RenderAction("MenuAction", "XMenu"); };

I renamed my Controller and my View.




@{ Html.RenderAction("MenuAction", "XMenu") };? I mean@char problem?@{ Html.RenderAction("MenuAction", "XMenu") }, without the second@and semicolon?