我第一次使用部分视图。在这个页面上,我在左侧有一个子菜单,根据菜单中点击的内容,我需要在右侧显示部分视图。
控制器:
public ActionResult PersoonsgebodenGegevens(string login)
{
ViewData["UserName"] = TempData["loginName"];
var LOGINNA = TempData["loginName"];
string loginNaam = GetLoginNaam((string)LOGINNA);
var model = new PersoneelsgegevensModel(loginNaam);
ViewBag.PartialViewName = "_Persoonsgegevens";
return View("PersoonsgebondenGegevens", model);
}
[HttpPost]
public ActionResult PersoonsgebondenGegevens(string ButtonSubMenu, FormCollection FC)
{
ViewData["UserName"] = TempData["loginName"];
var LOGINNA = TempData["loginName"];
string loginNaam = GetLoginNaam((string)LOGINNA);
var model = new PersoneelsgegevensModel(loginNaam);
switch (ButtonSubMenu)
{
case "Persoonsgegevens":
ViewBag.PartialViewName = "_Persoonsgegevens";
break;
case "Burgelijkestaat":
ViewBag.PartialViewName = "_Burgelijkestaat";
break;
case "Diploma":
ViewBag.PartialViewName = "_Diploma";
break;
case "Loopbaan/Verlof":
ViewBag.PartialViewName = "_LoopbaanVerlof";
break;
default:
break;
}
return View("PersoonsgebondenGegevens", model);
}
查看
@using (Html.BeginForm("PersoonsgebondenGegevens", "Home", FormMethod.Post, Html.RouteCollection == null))
{
if (Model.buttonJobClicked == true)
{
<div class="ContentLeft">
<div class="leftpart">
<div class="MenuHeader">Persoonsgebonden info</div>
<ul>
<li class="lili" id="1"><input id="button01" type="submit" value="Persoonsgegevens" name="ButtonSubMenu" /></li>
<li class="lili" id="2"><input id="button02" type="submit" value="Burgelijkestaat" name="ButtonSubMenu" /></li>
<li class="lili" id="3"><input id="button03" type="submit" value="Diploma" name="ButtonSubMenu" /></li>
<li class="lili" id="4"><input id="button04" type="submit" value="Loopbaan/Verlof" name="ButtonSubMenu" /></li>
</ul>
</div>
<div class="leftfooter"></div>
</div>
}
}
<div class="rightpart">
@{
Html.Partial((string)@ViewBag.PartialViewName);
}
</div>
如果我调试一切似乎没问题。模型将传递给我的部分视图,所有数据都会正确填充。但由于某些原因,我的父视图中没有显示部分视图。
有什么想法吗?
答案 0 :(得分:1)
尝试更改:
@{
Html.Partial((string)@ViewBag.PartialViewName);
}
到
@Html.Partial((string)ViewBag.PartialViewName)
[请注意,您不需要分号]