Link to home
Start Free TrialLog in
Avatar of atsherrill
atsherrill

asked on

How to do a SQL SELECT equivalent in ASP.NET 5 MVC 6, retrieving a single row from a database table

I went through the movie tutorial at https://docs.asp.net/en/latest/tutorials/your-first-aspnet-application.html and the MVA lessons at https://mva.microsoft.com/en-US/training-courses/introduction-to-aspnet-5-13786?l=PvSZtxoXB_5101937557. I *am* able to retrieve all rows in a SQL table in a cshtml file using code like this:

@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.CompanyName)
        </td>
         <!-- OTHER CODE HERE -->
    </tr>
}

But I am not yet able to retrieve a single row based on criteria passed in from a form.

Apparently, there is very little updated documentation on the newest release of ASP.NET 5 MVC 6.  I've done programming for many years, but I am new to ASP.NET. I am about to pull out what hair that I have left. I am trying to do a simple login, so I figured if I could just do a sql select with a where clause (passing in an email address and password from an HTML form), then I could retrieve a single row matching the "where" clause conditions; then I would have the beginnings of a successful login. Of course, I need to learn more about the proper way to program secure logins, but I can't even get a single row. All the documentation that I have seen refers to old ways of doing things, and I have read through many web pages on this topic. I've been working on this for almost two days, and I must get over this hurdle. Any help would be GREATLY appreciated.

Todd Sherrill
Avatar of YZlat
YZlat
Flag of United States of America image

Instead of using @html.displayfor(...)

Try

@item.CompanyName

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of atsherrill
atsherrill

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of atsherrill
atsherrill

ASKER

My comment describes the solution that I was originally looking for.