我想将月份和年份数据添加到数据库的下拉列表中。但是我收到了错误。所以任何帮助都可以适用。
这是我的观点:
@using (Html.BeginForm("ViewDataOfDatabase", "AirtelManagement",FormMethod.Post))
{
<p><h3>Find by PhoneNumber:@Html.TextBox("SearchString",ViewBag.CurrentFilter as string)</h3></p>
<p>Year:@Html.DropDownListFor(x => x.YearSelectedId, new SelectList(Model.YearList))
Month:@Html.DropDownListFor(x=>x.MonthSelectedId,new SelectList(Model.MonthList))</p>
<p><input type="submit" value="Search" /></p>
这是我的模特。
public class AirtelManagementModel
{
public long MobileAcNumber { get; set; }
public long AirtelNumber { get; set; }
public int OneTime { get; set; }
public float MonthlyCharges { get; set; }
public float CallCharges { get; set; }
public float ValueAddedServices { get; set; }
public float MobileInternetUsage { get; set; }
public float Roaming{ get; set; }
public float Discounts { get; set; }
public float Taxes { get; set; }
public float TotalCharges { get; set; }
public string WhoUploaded { get; set; }
public DateTime UploadedDate { get; set; }
public DateTime DateOfCreation { get; set; }
public int ImportDateId { get; set; }
public int MonthSelectedId { get; set; }
public List<AirtelManagementModel> MonthList
{
get;
set;
}
public int YearSelectedId { get; set; }
public List<AirtelManagementModel> YearList
{
get;
set;
}
}
这是存储库类&#39;我通过该方法从数据库中提取数据
public List<AirtelManagementModel> GetYearFromImportDate()
{
Database _db=DatabaseFactory.CreateDatabase("CCIDBConnection");
IDataReader _reader = _db.ExecuteReader("[dbo].GetYearFromDates");
List<AirtelManagementModel> _list = new List<AirtelManagementModel>();
while(_reader.Read())
{
AirtelManagementModel _model = new AirtelManagementModel();
_model.YearSelectedId = Convert.ToInt32(_reader["Id"]);
_model.YearList = (List<AirtelManagementModel>)_reader["YearOfDate"];
_list.Add(_model);
}
_reader.Close();
return _list;
}
答案 0 :(得分:0)
尝试使用SelectListItems列表而不是SelectList!
public List<SelectListItem> MonthList
{
get;
set;
}