问题
The error that I get is this (no more info) : System.StackOverflowException
Everything in my project is working fine but as soon as I post a data and after that, it should return view I get that error
and in my layout as soon as I remove the
part it working fine
@Html.Action("TuorMenu", "Home", new { area = "Site" })
simplify layout
@{
Layout = null;
}
<!DOCTYPE html>
html dir="rtl" lang="fa">
<head>
</head>
<body>
@Html.Action("TuorMenu", "Home", new { area = "Site" })
@RenderBody()
</body>
</html>
and the partial created like this
[HttpGet]
[OutputCache(Duration = 86400, VaryByParam = "none")]
[ChildActionOnly]
public ActionResult TuorMenu()
{
MenuViewModel vmg = new MenuViewModel();
vmg.TourGroup = _repoTourGroup.Where(p => p.Id != 15).ToList();
//vmg.BlogGroup = _repoBlogGroup.Select();
return PartialView("_TuorMenu", vmg);
}
...
@model test.ViewModels.Home.MenuViewModel
@{
Layout = null;
}
.......loading menu
I don't know is there anything wrong with the loading partial view or its just problem with returning view after HttpPost be its just forking fin in other pages but get that error when I try to access a view with a form HTTP post action
and about the HttpPost, let assume that there is view "A" that had the Form that is HttpPost and after that fires, we should get the created view BUT it just returns the above error
回答1:
just get your info in LayoutView if you using the DI first inject your repo
var _repoMenu = DependencyResolver.Current.GetService<IMenuRepository>();
var MenuModel = _repoMenu.Select();
then instead of
@Html.Action("TuorMenu", "Home", new { area = "Site" })
use partial
@Html.Partial("~/Areas/.../_TourMenu.cshtml",MenuModel)
来源:https://stackoverflow.com/questions/60136701/system-stackoverflowexception-after-httppost-returning-view-asp-mvc