这是我的部分视图,我的部分视图正在被重复使用,因此它没有强类型。
@if (Session["time"] != null)
{
MvcApplication6.Models.calendar cl = (MvcApplication6.Models.calendar)Session["time"];
var year = cl.schoolyear;
var term = cl.term;
}
<ul class="lispacer">
<li><a href="@Url.Action("Details", "Management")">View profile</a></li>
<li><a href="@Url.Action("Search", "Management")">Search Students</a></li>
<li><a href="@Url.Action("classes", "Management", new { schoolyear = , term = })">Manage Subjects</a></li>
<li><a href="@Url.Action("calendar", "Management")">Set Calendars</a></li>
</ul>
<form id="fooForm" action="@Url.Action("Logout", "Management")" method="post">
<a href="#" id="submit_link" class="button">Log out</a>
</form>
所以从这里开始,我有一个session
存储了一个类,我想在我的剃刀视图中检索它,但我不知道如何。
这是我需要它的代码行:
<li><a href="@Url.Action("classes", "Management", new { schoolyear = , term = })">Manage Subjects</a></li>
如何在链接中访问year
和term
变量?如果我直接在我的Url.Action
答案 0 :(得分:1)
您可以在year
语句范围之外声明term
和if
变量,因此,您可以在页面上访问它们。
var year = 0;
var term = "";
@if (Session["time"] != null)
{
MvcApplication6.Models.calendar cl = (MvcApplication6.Models.calendar)Session["time"];
var year = cl.schoolyear;
var term = cl.term;
}
<ul class="lispacer">
<li><a href="@Url.Action("Details", "Management")">View profile</a></li>
<li><a href="@Url.Action("Search", "Management")">Search Students</a></li>
<li><a href="@Url.Action("classes", "Management", new { schoolyear = , term = })">Manage Subjects</a></li>
<li><a href="@Url.Action("calendar", "Management")">Set Calendars</a></li>
</ul>
<form id="fooForm" action="@Url.Action("Logout", "Management")" method="post">
<a href="#" id="submit_link" class="button">Log out</a>
</form>
<li><a href="@Url.Action("classes", "Management", new { schoolyear = year, term = term })">Manage Subjects</a></li>