Note that there are some explanatory texts on larger screens.

plurals
  1. POCase Statements in LINQ query - AnonymousType to String?
    primarykey
    data
    text
    <p>I basically have the following:</p> <pre><code>public ActionResult Search(string searchString, string clientNo, int status = -1) { var statusLst = new List&lt;string&gt;(); var statusNoQry = from b in db.Briefs orderby b.Status select new { status = ( b.Status == 0 ? "Requested" : b.Status == 1 ? "In Progress" : "Undefined" ) }; statusLst.AddRange(statusNoQry.Distinct()); &lt;&lt;--- ERROR HERE ViewBag.status = new SelectList(statusLst); var ClientNoLst = new List&lt;string&gt;(); var ClientNoQry = from b in db.Briefs orderby b.Client_No_ where b.Client_Type == 0 select b.Client_No_; ClientNoLst.AddRange(ClientNoQry.Distinct()); ViewBag.clientNo = new SelectList(ClientNoLst); var briefs = from b in db.Briefs select b; Session["searchString"] = searchString; Session["clientNo"] = clientNo; if (!String.IsNullOrEmpty(searchString)) { briefs = briefs.Where(s =&gt; s.Client_No_.Contains(searchString) || s.Name.Contains(searchString)); } if ((status &gt; -1) &amp;&amp; (status &lt; 10)) { briefs = briefs.Where(y =&gt; y.Status == status); } if (string.IsNullOrEmpty(clientNo)) return View(briefs); else return View(briefs.Where(x =&gt; x.Client_No_ == clientNo)); } </code></pre> <p>However, I receive the following area:</p> <pre><code>Error 7 Argument 1: cannot convert from 'System.Linq.IQueryable&lt;AnonymousType#1&gt;' to 'System.Collections.Generic.IEnumerable&lt;string&gt;' </code></pre> <p>Status is of type int but I would like to cast it to string for my dropdownlist. I'm quite new to all this, what is the appropriate way of achieving this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload