我知道 MVC3 布局页面中只能存在 1 个 RenderBody,但我想尝试创建另一个。也许我以错误的方式看待它......理想情况下,我想添加一个从数据库中提取的推荐部分,并一次显示 1 个推荐,每个页面刷新或新页面显示一个不同的 1。解决此问题的最佳方法是什么?
Controller
CategoryDBContext db = new CategoryDBContext();
public ActionResult Testimonial(int id)
{
TestimonialModel model = db.Testimonials.Find(id);
return View(model);
}
模型
public class TestimonialModel
{
public int ID { get; set; }
public int CategoryID { get; set; }
public string Data { get; set; }
}
public class CategoryDBContext : DbContext
{
public DbSet<TestimonialModel> Testimonials { get; set; }
}
View 位于名为 CategoryData 的文件夹中。
最佳答案
你需要使用:
布局:
@RenderSection("Testimonial", false) @*false means that this section is not required*@
在你的视野中
@section Testimonial{
}
关于asp.net-mvc-3 - 布局页面中有两个渲染体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8809621/