1 回答
TA贡献1851条经验 获得超3个赞
控制器中的方法应该是一个 Action 并且它应该返回一个 ActionResult:
[HttpPost]
public ActionResult SetYear (Int32 intYear)
{
System.Web.HttpContext.Current.Session["Year"] = intYear;
return View();
}
此外,Select元素名称必须与 Action 方法的参数名称 ( intYear) 匹配:
@using (Html.BeginUmbracoForm<DataController>("SetYear", null, new { @id = "yearDropdown" }))
{
<div class="form-group">
<select id="Year" name="intYear" class="form-control">
@if (objModel.Annums != null)
{
foreach (Int32 intYear in objModel.Annums.OrderByDescending(x => x).ToList())
{
<option
@if (intYear == DateTime.Now.Year)
{
<text>selected</text>
}
value="@intYear">
@intYear
</option>
}
}
</div>
</div>
}
- 1 回答
- 0 关注
- 83 浏览
添加回答
举报