在我的_Layout.cshtml
文件中,我想调用如下内容:
<div id="content">
<div id="left-wrapper" class="box">
@Html.Action("FreeThisWeek", "Products")
@RenderBody()
</div>
</div>
这是我的 ProductsController 文件:
[ChildActionOnly]
public ActionResult FreeThisWeek()
{
//Some code that fetches the data and builds the model.
var model = BuildFreeProducts();
return View(model);
}
如果我尝试运行此代码,我会得到一个,StackOverflowException
因为 Action 返回 View(),它要求布局,它运行返回 View() 的 Action,依此类推。
可以理解,但是我该如何完成这个正确的代码呢?
我在哪里编写将这个数据模型与我编写的 HTML 复合的视图?