我有部分观点
if (CompanyFound != null)
{
Products = DB.tblBuyOnlineMasters.Where(c => c.CompanyID == CompanyID).OrderByDescending(p => p.BuyOnlineID).ToList();
if (Products.Count < 1)
{
ViewBag.Msg = "No products found for this company";
}
}
else
{
ViewBag.Msg = "Company Not Found (Showing result from all companies)";
}
我需要在主视图中显示数据
<div class="col-sm-8" style="background-color: rgb(231, 231, 231)">
@{
Html.RenderPartial("ProductRepeater");
}
<h4 style="text-align: center;">
@ViewBag.Msg
</h4>
</div>
ViewBag方法不传输数据
答案 0 :(得分:0)
我能够通过替换
来携带数据ViewBag.Msg
通过
TempData["Msg"]
我想知道这是否正常,或MVC中还有其他任何方法
视图看起来像
<div class="col-sm-8" style="background-color: rgb(231, 231, 231)">
@{
Html.RenderPartial("ProductRepeater");
}
<h4 style="text-align: center;">
@TempData["Msg"]
</h4>
</div>