我正在使用 mvc4 剃须刀,这是第一个模型代码
public class WebLicenses
{
    public string WebLicenseName { get; set; }
    public int CustomerWebLicensesCount { get; set; }
}
public class WebApplication
{
    public string WebApplicationName { get; set; }
    public int Count { get; set; }
    [DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
    public DateTime? EndDate { get; set; }
    public string Never { get; set; }
}
public class griddetail
{
    public griddetail( List<WebLicenses> wl1,List<WebApplication> wa1 )
    { 
        wl =wl1;
        wa = wa1;
    }
    //public List<WebLicenses> wl2 { get; private set; }
    public List<WebLicenses> wl { get; set; }
    public List<WebApplication> wa { get; set; }
}
这是我的第二个模型代码,它使用第一个模型代码作为(这里存储过程返回 2 个表 - WebLicenses,WebApplication(在下面的代码中出现错误——注释)
public IEnumerable GetOutlookGridDetail(string customerId = "")
{
        List<WebLicenses> weblicenses = new List<WebLicenses>();
        List<WebApplication> webapplication = new List<WebApplication>();            
        griddetail returnValue = new griddetail(weblicenses, webapplication);          
        SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["SLIMConnectionString"].ConnectionString);
        SqlCommand cmd = new SqlCommand("selectCustomerDetail", cn);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlParameter param_CustomerID = new SqlParameter("@CustomerID", SqlDbType.VarChar, 10);
        param_CustomerID.Value = customerId;
        cmd.Parameters.Add(param_CustomerID);
        try
        {
            cn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                WebLicenses newRecord = new WebLicenses();
                newRecord.WebLicenseName = Convert.ToString(reader["WebLicenseName"]);
                newRecord.CustomerWebLicensesCount = Convert.ToInt32(reader["CustomerWebLicensesCount"]);
                //returnValue.Add(newRecord);
                weblicenses.Add(newRecord);                    
            }
            reader.NextResult();
            while (reader.Read())
            {
                WebApplication newRecord = new WebApplication();
                newRecord.WebApplicationName = Convert.ToString(reader["WebApplicationName"]);
                newRecord.Count = Convert.ToInt32(reader["Count"]);
                newRecord.Never = Convert.ToString(reader["Never"]);
                webapplication.Add(newRecord);
            }
            returnValue.wl.Add(weblicenses); //here comes error (Argument 1: cannot convert from 'System.Collections.Generic.List<SLIM.Models.WebLicenses>' to 'SLIM.Models.WebLicenses')
        }
        catch (Exception)
        {
            // returnValue = null;
        }
        finally
        {
            cmd.Dispose();
            if (cn.State == ConnectionState.Open)
            {
                cn.Close();
            }
        }
        return returnValue;
}
这是我的控制器代码。
    [HttpPost]
    public ActionResult GridViewPartialView(string recordId)
    {
        IEnumerable result1 = (new SlimHomePageData()).GetRecords(recordId, "");
        IEnumerable result2 = (new SlimHomePageData()).GetRecords();
        List<object> finalResult = new List<object>();
        finalResult.Add(result1);
        finalResult.Add(result2);
        return PartialView("OutlookGridDetail", finalResult);            
    }
我想返回一个包含 2 个列表的列表(但出现上述错误)。还建议,这是正确的方法,因为存储过程返回多个表,我们想通过模型在视图中设置值。