我需要在部分视图中使用ViewBag / TempData值,该值从控制器通过视图传递。 controlller.cs
var category = (from s in context.M_ProductCategory
where s.ID == C_ID
select s.Title);
ViewBag.cat = category;
Index.cshtml
@{
Html.RenderPartial("PartialViewSpecification", new { ProductCategory = @ViewBag.cat });
}
我需要在PartialViewSpecification中使用ViewBag.cat的值。请帮助
答案 0 :(得分:0)
尝试这种方式: 控制器:
var category = (from s in context.M_ProductCategory
where s.ID == C_ID
select s.Title);
ViewBag.cat = category.FirstOrDefault();
Index.cshtml:
@{
Html.RenderPartial("PartialViewSpecification");
}
PartialViewSpecification.cshtml(partialView):
@ViewBag.cat
我希望这个有效......
答案 1 :(得分:0)
<强> Index.cshtml:强>
@{
Html.RenderPartial("PartialViewSpecification", (string)(ViewBag.cat));
}
<强> PartialViewSpecification.cshtml 强>:
@model string
<span>Model</span>