Click here to Skip to main content
14,429,289 members
Rate this:
Please Sign up or sign in to 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:

[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);
        }


@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 23:32pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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;
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100