title: Send LINQ result to another function in ASP.NET MVC
body: <p>I am developing a controller in which I consult information and the results are shown in the view of my controller and I send them via email by pressing a  "Send Email" button.</p>
  
  <p>Here is an example:</p>
  
  <p><img src="https://i.stack.imgur.com/rUP0b.gif" alt="Example"></p>
  
  <p>But when I want to pass my LINQ results to the <code>SendEmail()</code> method, I get an error.</p>
  
  <p>The LINQ results are:</p>
  
  <p><a href="https://i.stack.imgur.com/ihnNr.png" rel="nofollow noreferrer">Issue when i press Send Email button</a></p>
  
  <p>Here is my controller</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Text;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Net.Mail;
  using System.Web.Mvc;
  
  namespace MvcInventory.Controllers
  {
      public class HomeController : Controller
      {
          public ActionResult Index()
          {
              Entities db = new Entities();
              var s = from sw in db.TB_RS_PROD.Where(x =&gt; x.IDPROD == 1)
                      select sw;
              ViewData["email"] = s;
              return View(s);
          }
  
          protected string RenderPartialViewToString(string viewName, object model)
          {
              if (string.IsNullOrEmpty(viewName))
                  viewName = ControllerContext.RouteData.GetRequiredString("action");
  
              ViewData.Model = model;
  
              using (StringWriter sw = new StringWriter())
              {
                  ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
                  ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
                  viewResult.View.Render(viewContext, sw);
  
                  return sw.GetStringBuilder().ToString();
              }
          }
  
          public ActionResult SendEmail()
          {
              var htmlp = RenderPartialViewToString("~/Views/Home/Index.cshtml", ViewData["email"]);
              SmtpClient SmtpServer = new SmtpClient();
              MailMessage mail = new MailMessage();
              SmtpServer.Credentials = new System.Net.NetworkCredential("IT@serv.com", "");
              SmtpServer.Port = 25;
              SmtpServer.Host = "150.147.12.155";
              mail = new MailMessage();
              mail.From = new MailAddress("IT@serv.com", "IT TEAM");
              mail.To.Add("sz@serv.com");
              mail.Subject = "Request";
              mail.IsBodyHtml = true;
              mail.Body = htmlp;
              mail.Priority = MailPriority.High;
              SmtpServer.Send(mail);
              return View("~/Views/Home/About.cshtml");
          }
      }
  }
  </code></pre>
  
  <p>My view</p>
  
  <pre><code>@model IEnumerable&lt;MvcInventory.TB_RS_PROD&gt;
  @{
  }
  &lt;html&gt;
  &lt;table class="table table-striped"&gt;
      &lt;tr&gt;
          &lt;td&gt;ID PRODUCT&lt;/td&gt;
          &lt;td&gt;PRODUCT NAME&lt;/td&gt;
          &lt;td&gt;QUIANTITY&lt;/td&gt;
          &lt;td&gt;DATE&lt;/td&gt;
          &lt;td&gt;STATUS&lt;/td&gt;
      &lt;/tr&gt;
      @foreach (var item in Model)
      {
          &lt;tr&gt;
             &lt;td&gt;@item.IDPROD&lt;/td&gt;
             &lt;td&gt;@item.PROD_NAME&lt;/td&gt;
             &lt;td&gt;@item.QUANTITY&lt;/td&gt;
             &lt;td&gt;@item.UPDATE_DATE&lt;/td&gt;
             &lt;td&gt;@item.STATUS&lt;/td&gt;
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  &lt;button onclick="location.href='@Url.Action("SendEmail","Home")'"&gt;Send Email&lt;/button&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>I wanted to do it through <code>ViewData["email"]</code> since I understand that this way the values ​​can be passed.</p>
  
  <p>Even so, I don't know how to solve this problem. It works if i put a static value but i need to put the LINQ result.</p>
  
  <p>What should I do so that when I click the button I can send the email?</p>
  
  <p>Thank you.</p>