asp.netdatabaseasp.net-mvc-3sql-server-2008

How to display all records from the table ASP.NET MVC 3


I have db with this table (TableToDo):

enter image description here

I want display all records in TableToDo where login==Joe.

All records I display so: Controller:

ASPNETDBEntities __db = new ASPNETDBEntities();
public ActionResult Index(TableToDo obj)
{
    var th = (from TableToDo in __db.TableToDo select TableToDo).ToList();

    return View(th);
}

and strongly-typed View(List):

@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.text)
        </td>
        <td>
            @Html.ActionLink("x", "Delete", new { id = item.id })
        </td>
    </tr>
}

Please tell me how display all records in TableToDo where login==Joe?


Solution

  • You have to do that when you get the data from the data source. So update your query to

     var th = (from TableToDo in __db.TableToDo where TableToDo.Login="Joe" select TableToDo).ToList();