title: Null reference in Model
body: <p>I am having this problem when i press a link to view data in pdf:</p>
  
  <p><a href="https://i.stack.imgur.com/lqf25.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lqf25.png" alt="enter image description here"></a></p>
  
  <pre><code>System.NullReferenceException: 'Object reference not set as an instance of an object.'
  </code></pre>
  
  <p>This problem arises when I try to display the SQL values ​​in PDF.</p>
  
  <p><a href="https://i.stack.imgur.com/jwC7O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jwC7O.png" alt="enter image description here"></a></p>
  
  <p>As you can see in the image, there is a link to see the values ​​in PDF, when you click there the error already mentioned will appear.</p>
  
  <p>I share the code:</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>public ActionResult Index(string buscarTitulo)
          {
              PDFPrinter db = new PDFPrinter();
              ViewBag.CurrentFilter = buscarTitulo;
  
              var datos = from s in db.SQLs
                          select s;
              if (!String.IsNullOrEmpty(buscarTitulo))
              {
                  datos = datos.Where(s =&gt; s.Titulo.ToString().Contains(buscarTitulo.ToUpper()));
              }
              return View(datos.ToList());
          }
  
          public ActionResult Pdf()
          {
              var reporte = new ActionAsPdf("Index");
              return reporte;
          }
  
          public ActionResult Impresion(double? tit) {
              using (PDFPrinter db = new PDFPrinter()) {
                  V_CuetaWeb v = db.SQLs.FirstOrDefault(c =&gt; c.Titulo == tit);
                  List&lt;V_CuetaWeb&gt; lista = new List&lt;V_CuetaWeb&gt;();
                  lista.Add(v);
                  var reporte = new PartialViewAsPdf("Pdf", v);
                  return reporte;
              }
          }
  </code></pre>
  
  <p><strong>Index:</strong></p>
  
  <pre><code>@model IEnumerable&lt;ProvidusCuotas.V_CuetaWeb&gt;
  
  
  @{
      ViewBag.Title = "Inicio";
  }
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta name="viewport" content="width=device-width" /&gt;
      &lt;title&gt;Inicio&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form"&gt;
          &lt;div&gt;
              @using (Html.BeginForm())
              {
                  &lt;p&gt;
                      Título: @Html.TextBox("buscar", ViewBag.CurrentFilter as string)
                      &lt;input type="submit" value="Filtrar" /&gt;&lt;br /&gt;
                      &lt;input type="button" value="Imprimir" onclick="window.print()" /&gt;
                  &lt;/p&gt;
              }
          &lt;/div&gt;
          &lt;div&gt;
              &lt;table border="1"&gt;
                  @foreach (var item in Model)
                  {
                      &lt;tr&gt;
                          &lt;th scope="row" abbr="Suscriptor"&gt;Suscriptor: &lt;/th&gt;
                          &lt;td&gt;
  
                              &lt;b&gt;@Html.DisplayFor(modelItem =&gt; item.Apellido), @Html.DisplayFor(modelItem =&gt; item.Nombre)&lt;/b&gt;
                          &lt;/td&gt;
                          &lt;td&gt;Título: @Html.DisplayFor(modelItem =&gt; item.Titulo)&lt;/td&gt;
                      &lt;/tr&gt;
  </code></pre>
  
  <p><strong>PDF:</strong></p>
  
  <pre><code>@model IEnumerable&lt;ProvidusCuotas.V_CuetaWeb&gt;
  
  @{
      ViewBag.Title = "PDF";
  }
  
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta name="viewport" content="width=device-width" /&gt;
      &lt;title&gt;Inicio&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form"&gt;
          &lt;div&gt;
              &lt;table border="1"&gt;
                  @foreach (var item in Model)
                  {
                      &lt;tr&gt;
                          &lt;th scope="row" abbr="Domicilio"&gt;Domicilio: &lt;/th&gt;
                          &lt;td&gt;
                              @Html.DisplayFor(modelItem =&gt; item.Domicilio)
                          &lt;/td&gt;
                          &lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;&lt;/td&gt;
                          &lt;td&gt;Valor Nominal: @Html.DisplayFor(modelItem =&gt; item.ValNom)&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;th scope="row" abbr="Barrio"&gt;Barrio: &lt;/th&gt;
                          &lt;td&gt;
                              @Html.DisplayFor(modelItem =&gt; item.Barrio)
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;th scope="row" abbr="Localidad"&gt;Localidad: &lt;/th&gt;
                          &lt;td&gt;
                              @Html.DisplayFor(modelItem =&gt; item.Localidad)
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;th scope="row" abbr="Telefono"&gt;Teléfono: &lt;/th&gt;
                          &lt;td&gt;
                              @Html.DisplayFor(modelItem =&gt; item.Telefono)
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;th scope="row" abbr="Celular"&gt;Celular: &lt;/th&gt;
                          &lt;td&gt;
                              @Html.DisplayFor(modelItem =&gt; item.Celular)
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;th scope="row" abbr="Descripcion"&gt;D. Plan Actual: &lt;/th&gt;
                          &lt;td&gt;
                              @Html.DisplayFor(modelItem =&gt; item.DescPlanActual)
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;th scope="row" abbr="Fecha"&gt;Fecha Sorteo: &lt;/th&gt;
                          &lt;td&gt;
                              @Html.DisplayFor(modelItem =&gt; item.FechaSorteo)
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;th&gt;Zona: @Html.DisplayFor(modelItem =&gt; item.acidzona)&lt;/th&gt;
                          &lt;th&gt;Cobrador: @Html.DisplayFor(modelItem =&gt; item.Cobrador)&lt;/th&gt;
                          &lt;th&gt;Código: @Html.DisplayFor(modelItem =&gt; item.Codigo)&lt;/th&gt;
                          &lt;th&gt;Título: @Html.DisplayFor(modelItem =&gt; item.Titulo)/@Html.DisplayFor(modelItem =&gt; item.Endoso)&lt;/th&gt;
                          &lt;th&gt;Sorteo: @Html.DisplayFor(modelItem =&gt; item.Sorteo)&lt;/th&gt;
                          &lt;th&gt;Cuota: @Html.DisplayFor(modelItem =&gt; item.Cuota)&lt;/th&gt;
                          &lt;th&gt;Vencimiento: @Html.DisplayFor(modelItem =&gt; item.Vencimiento)&lt;/th&gt;
                          &lt;th&gt;Monto: @Html.DisplayFor(modelItem =&gt; item.Monto)&lt;/th&gt;
                      &lt;/tr&gt;
                  }
              &lt;/table&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>PDFPrinter class:</strong></p>
  
  <pre><code>public partial class PDFPrinter : DbContext
      {
          public PDFPrinter()
              : base("name=VisorPDF")
          {
          }
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              throw new UnintentionalCodeFirstException();
          }
  
          //public virtual DbSet&lt;V_CuetaWeb&gt; V_CuetaWeb { get; set; }
  
          public virtual DbSet&lt;V_CuetaWeb&gt; SQLs { get; set; }
      }
  </code></pre>
  
  <p>Any sugerence? how to solve this?
  I don't understan the mistake</p>