【发布时间】:2015-08-09 21:19:44
【问题描述】:
我知道这是很多人在网站上回答的问题,但似乎没有解决方案可以解决我的问题。 我是 MVC 新手,不知道如何将下拉列表中的选定项目发送到控制器。
public class MonthDropDownList
{
public IEnumerable<SelectListItem> Months
{
get
{
return DateTimeFormatInfo
.InvariantInfo
.MonthNames
.Where(m => !String.IsNullOrEmpty(m) )
.Select((monthName, index) => new SelectListItem
{
Value = (index + 1).ToString(),
Text = monthName
});
}
}
public int SelectedMonth { get; set; }
}
这是我的看法:
@model Plotting.Models.MonthDropDownList
@Html.DropDownListFor(x => x.SelectedMonth, Model.Months)
@using (Html.BeginForm("MonthlyReports", "Greenhouse", FormMethod.Post))
{
<input type="submit" name="btnSubmit" value="Monthly Report" />
}
这是我应该使用所选日期的 ActionResult :
public ActionResult MonthlyReports(MonthDropDownList Month)
{
Debug.Write("Month" + Month.SelectedMonth);// <- always = 0
InitChartModel();
cDate.DateTitle = "Day";
string msg = dal.Connection("month");
List<Greenhouse> greenhouse = dal.FindIfDMY("month" , Month.SelectedMonth , msg);
cDate.DateData = GetChart(greenhouse, "month");
return View("MonthlyReports", cDate);
}
【问题讨论】:
标签: c# asp.net asp.net-mvc html.dropdownlistfor