MVC 将消息从部分视图传递到视图
MVC pass Message from Partial View to View
我有部分看法
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 方法未传输数据
我能够通过替换
来携带数据
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>
我有部分看法
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 方法未传输数据
我能够通过替换
来携带数据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>