Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 在数据库的下拉列表中添加年份和月份_Asp.net Mvc 3_Razor 2 - Fatal编程技术网

Asp.net mvc 3 在数据库的下拉列表中添加年份和月份

Asp.net mvc 3 在数据库的下拉列表中添加年份和月份,asp.net-mvc-3,razor-2,Asp.net Mvc 3,Razor 2,我想将月份和年份数据添加到数据库的下拉列表中。但我有个错误。因此,任何帮助都是值得的 我的看法是: @using (Html.BeginForm("ViewDataOfDatabase", "AirtelManagement",FormMethod.Post)) { <p><h3>Find by PhoneNumber:@Html.TextBox("SearchString",ViewBag.CurrentFilter as string)</h3

我想将月份和年份数据添加到数据库的下拉列表中。但我有个错误。因此,任何帮助都是值得的

我的看法是:

 @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>
@使用(Html.BeginForm(“ViewDataOfDatabase”,“AirtelManagement”,FormMethod.Post))
{
按电话号码查找:@Html.TextBox(“SearchString”,ViewBag.CurrentFilter为字符串)

年份:@Html.DropDownListFor(x=>x.YearSelectedId,新的SelectList(Model.YearList)) 月份:@Html.DropDownListFor(x=>x.MonthSelectedId,新选择列表(Model.MonthList))

这是我的模型

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;
    }
}
公共类AirtelManagementModel
{
公共长移动号码{get;set;}
公共长AirtelNumber{get;set;}
公共int一次性{get;set;}
公共浮动月收费{get;set;}
公共浮动通话费{get;set;}
公共浮点值AddedServices{get;set;}
公共浮动MobileInternetUsage{get;set;}
公共浮动漫游{get;set;}
公共浮动折扣{get;set;}
公共浮动税{get;set;}
公共浮动总费用{get;set;}
公共字符串{get;set;}
公共日期时间上载日期{get;set;}
创建的公共日期时间日期{get;set;}
public int ImportDateId{get;set;}
public int MonthSelectedId{get;set;}
公开名单月刊
{
得到;
设置
}
public int YearSelectedId{get;set;}
公众名单
{
得到;
设置
}
}
这是repository类的方法,我通过它从数据库中获取数据

     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;
    }
公共列表GetYearFromImportDate()
{ 
Database _db=DatabaseFactory.CreateDatabase(“CCIDBConnection”);
IDataReader _reader=_db.ExecuteReader(“[dbo].GetYearFromDates”);
列表_List=新列表();
而(_reader.Read())
{
AirtelManagementModel_model=新的AirtelManagementModel();
_model.YearSelectedId=Convert.ToInt32(_reader[“Id]”);
_model.YearList=(List)u读取器[“YearOfDate”];
_列表。添加(_模型);
}
_reader.Close();
返回列表;
}

尝试使用SelectListItems列表而不是SelectList

  public List<SelectListItem> MonthList
  {
    get;
    set;
  }
公共列表月列表
{
得到;
设置
}

AirtelManagementModel不包含YearSelectId的定义,并且找不到接受PagedList.IPagedList类型的第一个参数的扩展方法YearSelectedId。