Using Store Procedure Select Data From Two Table And Get List In MVC

 Controller

 public ActionResult StudentDetail()
        {
            var Data = _context.Database.SqlQuery<Your Class >("YourStoreProcedre Name").ToList();
            return View(Data);
        }


View


@model IEnumerable<interview2.Models.StudentViewModel>

@{
    ViewBag.Title = "StudentDetail";
}

<h2>StudentDetail</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Maths)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Phy)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.chemestriy)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Streem)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ContactNumber)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Address)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Maths)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Phy)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.chemestriy)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Streem)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ContactNumber)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Address)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
            @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
            @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
        </td>
    </tr>
}

</table>



Alter PROCEDURE  SelectStudentDetail
As
BEGIN 
select StudentDetail.[Name] ,StudentDetail.ContactNumber ,StudentDetail.Streem,StudenMarks.Maths,StudenMarks.phy,StudenMarks.chemestriy
From StudentDetail
Full Join StudenMarks ON StudentDetail.StudentId=StudenMarks.id;
End




Table 1 (StudentMarks)


Id int Unchecked
Maths int Checked
Phy int Checked
chemestriy int Checked

Table 2(StudentDetail)


StudentId int Unchecked
Name varchar(50) Checked
Streem varchar(50) Checked
ContactNumber varchar(15) Checked
Address varchar(100) Checked

Comments

Popular posts from this blog

Search Record From Table Using jQuery in Asp.net core MVC

How To insert Radio Button Data in DataBase -- MVC

Toolbox Webparts Controls