jeudi 30 mars 2017

Fetching Data from Database and display in View by using MVC entity frame work

I am creating one application by using MVC entity framework. In my application user will login with email ID and will enter the task details and later user can able to view the data which saved. Unfortunately not able to display the data for particular user as all the users data coming into the view. Below is the code for the Controller

   public ActionResult TaskDetails(string td)
        {
            using (Data DE = new Data())
            {
                var email = Session["Email"].ToString();
                var displaydata = DE.TaskDetails.Where(u => u.ProjectID.ToString() == email).ToList();
                ViewBag.details = displaydata;

                return View();
            }
        }

Here email id is from one table and projectID from one table and by using primary key I am trying to get the data. But unfortunately all the users data is coming. This is code for my View @model MVC_Sample.Models.TaskDetail @{ Layout = null; }

@using (Html.BeginForm("TaskDetails", "Home", FormMethod.Post))
{
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>TaskDetails</title>
</head>
<body>
    <div> 
        @foreach (var item in ViewBag.details)

        {
            <table id="t01">
                <tr>
                    <td>@item.ProjectID</td>
                    <td>@item.ProjectName</td>
                    <td>@item.StartDate</td>
                    <td>@item.EstimatedDate</td>
                    <td>@item.TaskDescription</td>
                </tr>

            </table>
        }
    </div>
</body>
</html>

Can any one help me to find where I did mistake.

Aucun commentaire:

Enregistrer un commentaire