如何使用TempData从表中获取受尊重的数据[" Id"]

时间:2015-06-26 13:46:35

标签: asp.net-mvc kendo-ui asp.net-mvc-5

我是这个Kendo UI网格,我用几个表中的值填充网格 我有这个 GetBrands 方法,我可以从其他表中获取vales,因为您可以在给定的方法中看到我能得到的是来自TemData的数据[" CompanyId"] 如何从此

获取 CompanyName
 public ActionResult GetBrands([DataSourceRequest] DataSourceRequest request)
        {
            var result= new DataSourceResult();
            IQueryable<Brand> brands = null;
            try
            {
                brands = db.Brands;
                result = brands.AsQueryable()
                    .ToList()
                    .Select(b => new BrandListViewModels()
                    {
                        BrandName = b.BrandName,
                        ProductGroupCode = b.ProductGroupCode !=null? db.ProductGroups.FirstOrDefault(p => p.ProductGroupCode==b.ProductGroupCode).ProductGroupName:"N/A",
                        ProductSubGroupCode = b.ProductGroupCode != null ? db.ProductSubGroups.FirstOrDefault(p => p.ProductSubGroupCode == b.ProductSubGroupCode).ProductSubGroupName : "N/A",
                       // CompanyId = Convert.ToInt32(TempData["CompanyId"]) !=null? int.TryParse(db.Companies.FirstOrDefault(c=>c.Id==b.CompanyId).CompanyName, out id):"N/A"
                    }).OrderBy(b=>b.CompnayName)
                    .ToDataSourceResult(request);
            }
            catch (Exception ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
                //Temporary storing notification message
                TempData["MESSAGE"] = js.Serialize(new { message = "Error has been occured while populating brands", type = "E" });
            }
            return Json(result,JsonRequestBehavior.AllowGet);
        }

我试图转换它并做很多其他的东西,但它不工作它的类型是Int

修改

这是我的BrandListViewModel

 public class BrandListViewModels
{
    public string ProductGroupCode { get; set; }
    public string ProductSubGroupCode { get; set; }
    public string BrandCode { get; set; }
    public string BrandName { get; set; }
    public int CompanyId { get; set; }       
    public string CompnayName { get; set; }

}

这是我的网格

 @(Html.Kendo().Grid(Model)
      .Name("BrandGrid")
      .Columns(columns =>
          {
              columns.Bound(c => c.CompanyId).Title("Company");
              columns.Bound(c => c.BrandName).Title("Brand");
              columns.Bound(c => c.ProductGroupCode).Title("Product Group");
              columns.Bound(c => c.ProductSubGroupCode).Title("Product Sub Group");

0 个答案:

没有答案