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 關注
- 116 瀏覽
添加回答
舉報