[RESOLVED]MVC C#

In below code filterData is holding correct records but not filling the correct value to rep.reports.
There might be some error while assigning coz I do not remember but in actual it is correct if I enter some other value apart from a it is giving correct value. Shows no result but if name starts with a then it displays all records.

<div>Inside filterdata is holding correct value but outside the loop it is putting all records in rep.reports.</div> <div></div> <div>Please correct that, as per my knowledge prob is only in bolded one.</div> <div>
<div></div> <div>
public class Report
{
List<Report> reports{get;set;}
}

public ActionResult getRecipient(string RecipientName)
{
List<Reports> lstReports=new List<Reports>();
// lstReports has records
Report rep=new Report()P;
IEnumerable<Report> filterData=new List<Report>();
foreach(var reports in lstReports)
{
if( RecipientName=="all" || RecipientName.ToLower().StartsWith("a"))
{
filterData= from x in select Reports where(); 
}
}
rep.reports=filterData.ToList();
return PartialView("", rep);

}</div>

</div>

Hi,

As per my understanding, show all data for "all" or some data for ‘a’.
Try updating ur code like this:

IEnumerable<Report> filterData=new List<Report>();
if( RecipientName=="all")
{
    filterData=lstReports;
}
else if(RecipientName.ToLower().StartsWith("a"))
{
    filterData= (from t in lstReports
                where SqlMethods.Like(t.urProperty, "%a%") //update urProperty
                select t);
}
rep.reports=filterData.ToList();

Leave a Reply