Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.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
C# 转换为值类型“System.Int32”失败,因为具体化的值为null_C#_Asp.net Mvc_Entity Framework_Crystal Reports - Fatal编程技术网

C# 转换为值类型“System.Int32”失败,因为具体化的值为null

C# 转换为值类型“System.Int32”失败,因为具体化的值为null,c#,asp.net-mvc,entity-framework,crystal-reports,C#,Asp.net Mvc,Entity Framework,Crystal Reports,这是我的家庭控制器: using System; using System.Collections.Generic; using System.Data.Entity; using System.IO; using System.Linq; using System.Web; using System.Web.Mvc; using Biblioteca.Models; using CrystalDecisions.CrystalReports.Engine; namespace Bibliot

这是我的家庭控制器:

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Biblioteca.Models;
using CrystalDecisions.CrystalReports.Engine;

namespace Biblioteca.Controllers
{
    public class HomeController : Controller
    {
        private BibliotecaDatabase db = new BibliotecaDatabase();

        public ActionResult Index()
        {
            var totalesviewmodel = new TotalesViewModel();
            totalesviewmodel.MontoCopias = db.AlumnosList.Sum(o => o.Copias);
            totalesviewmodel.MontoImpresiones = db.AlumnosList.Sum(o => o.Impresiones);
            totalesviewmodel.DineroDeposito = db.AlumnosList.Sum(o => o.Deposito);
            totalesviewmodel.DineroSap = db.AlumnosList.Sum(o => o.Sap);
    // *** here is my issue ***
            totalesviewmodel.MontoCopiasMaestro = db.MaestrosList.Sum(o => o.Copias);
            totalesviewmodel.MontoImpresionesMaestro = db.MaestrosList.Sum(o => o.Impresiones);
            return View(totalesviewmodel);
        }

        public ActionResult Reports()
        {
            List<Alumno> allDatos = new List<Alumno>();
            using (BibliotecaEntities dc = new BibliotecaEntities())
            {
                allDatos = dc.Alumnos.ToList();
            }
            return View(allDatos);
        }

        public ActionResult ExportReport()
        {
            List<Alumno> allDatos = new List<Alumno>();
            using (BibliotecaEntities dc = new BibliotecaEntities())
            {
                allDatos = dc.Alumnos.ToList();

                ReportDocument rd = new ReportDocument();
                rd.Load(Path.Combine(Server.MapPath("~/Reports"), "rpt_datos.rpt"));
                rd.SetDataSource(allDatos);

                Response.Buffer = false;
                Response.ClearContent();
                Response.ClearHeaders();

                try
                {
                    Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                    stream.Seek(0, SeekOrigin.Begin);
                    return File(stream, "application/pdf", "Reporte.pdf");
                }
                catch (Exception ex)
                {
                    throw;
                }
            }
        }

        public ActionResult Contact ()
        {
            ViewBag.Message = "Your contact page.";
            return View();
        }
    }
}
我得到这个错误:

转换为值类型“System.Int32”失败,因为具体化的值为null

在安装crystal reports之前,我没有这个问题


我做错了什么?

我解决了它,当您在数据库中没有任何注册表时会发生错误,因此您需要插入一个注册表才能正常工作:D

totalesviewmodel.MontoCopias的类型是什么?它应该是像int?一样的可空类型。是的,我有maestroslistyap我的字段是int?在db.MaestrosList.Sumo=>o.Copias中,o.Copias的类型是什么?
totalesviewmodel.MontoCopiasMaestro = db.MaestrosList.Sum(o => o.Copias);