Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to search and for records in the DB and display. But the search is not working i am getting an error like Error = The function evaluation requires all threads to run. The dbcontext not returning any rows.

What I have tried:

C#
[HttpPost]
        public ActionResult Search( string Search)
        {
             
            var emp = from m in db.Emps
                      select m;

            if (emp != null)
            {
              var ttt = db.Emps.Where(s => s.Name.Contains(Search));
               
            }

            else
            {
                ModelState.AddModelError("Name"," No records found");

            }
            return View(emp);
        }


HTML
@using (Html.BeginForm("Search", "Emps", FormMethod.Post))
{

    <div class="container form-group">
        <input class="form-control" type="text" id="Mail" name="Search">

    </div>

    @*@Html.TextBox("SearchText")*@
    <div class="form-group">
        <input type="submit" value="Search" id="searching" class="btn btn-default mysquare" />
    </div>

}

@if (Model != null)
{
    foreach (var person in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelitem => person.ID)
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayFor(modelitem => person.Name)
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayFor(modelitem => person.City)
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayFor(modelitem => person.Designation)
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayFor(modelitem => person.Country)
            </td>
        </tr>
        <tr>
            <td>
                @Html.DisplayFor(modelitem => person.Mail)
            </td>
        </tr>
    }
}
Posted
Updated 19-Dec-18 22:32pm

1 solution

have a read of this

c# - Visual Studio during Debugging: The function evaluation requires all threads to run - Stack Overflow[^]

without knowing where the exception is raised I can't suggest anything other than having a read of the above.

Plus I would also change the code to something like the following

var foundEmployees = db.Emps.Where(s => s.Name.Contains(Search));
if(foundEmployees == null) ModelState.AddModelError("Name"," No records found");
return foundEmployees;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900