for the first time I'm using Partial Views. On this page I have a sub menu on the left and based on what is clicked in the menu I need to show a partial view on the right.
我第一次使用部分视图。在这个页面上,我在左侧有一个子菜单,根据菜单中点击的内容,我需要在右侧显示部分视图。
Controller:
控制器:
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);
}
View
视图
@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>
If I debug everything seems to be ok. The model gets passed to my Partial Views and all data get filled in correctly. But for some reason no Partial View shows in my parent view.
如果我调试一切似乎没问题。模型将传递给我的部分视图,所有数据都会正确填充。但由于某种原因,我的父视图中没有显示部分视图。
Any ideas?
有任何想法吗?
1 个解决方案
#1
1
Try changing:
尝试改变:
@{
Html.Partial((string)@ViewBag.PartialViewName);
}
to
至
@Html.Partial((string)ViewBag.PartialViewName)
[note that you don't need the semicolon]
[注意你不需要分号]
#1
1
Try changing:
尝试改变:
@{
Html.Partial((string)@ViewBag.PartialViewName);
}
to
至
@Html.Partial((string)ViewBag.PartialViewName)
[note that you don't need the semicolon]
[注意你不需要分号]