Aufrufen und Ausführen gespeicherter Prozeduren in ASP.Net MVC (C #)

Guten Tag Leute, ich bin hier in einer kleinen Schwebe. Ich habe meine Datenbank, mein Modell, meinen Controller und meine Ansicht in Visual Studio mit ASP.NET MVC und C # erstellt, kann aber nicht herausfinden, wie eine gespeicherte Prozedur aufzurufen ist, die ich ebenfalls erstellt habe.

Ich möchte, dass die gespeicherte Prozedur auf einer Schaltfläche aufgerufen wird, die ich in meiner Ansicht platziert habe. Diese gespeicherte Prozedur sollte ausgeführt werden und Ergebnisse anzeigen, wenn auf die Schaltfläche geklickt wird. Nachfolgend sind die von mir erstellte gespeicherte Prozedur, Ansicht, Modell und Steuerung aufgeführt.

Dies ist mein 'Mitarbeiter'-Modell:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentM,odel.DataAnnotations.Schema;
using System.Linq;
using System.Web;

namespace MVCSimpleApp.Models
{
    [Table("Employees")]
    public class Employee
    {
        [Display(Name ="Employee Id")]
        public int EmployeeId { get; set; }
        [Display(Name ="First Name")]
        public string FirstName { get; set; }
        [Display(Name ="Last Name")]
        public string LastName { get; set; }
    }
}

Dies ist mein Datenkontext:

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace MVCSimpleApp.Models
{
    public class EmployeeContext : DbContext
    {
        public DbSet<Employee> Employee { get; set; }
    }
}

Das ist mein Employee Controller:

using MVCSimpleApp.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;

namespace MVCSimpleApp.Controllers
{
    public class EmployeeController : Controller
    {
        private EmployeeContext db = new EmployeeContext();
        // GET: Employee
        public ActionResult Index()
        {

            var employees = from e in db.Employee select e;
            return View(employees);
        }
    }
 }

Und jetzt ist dies meine gespeicherte Prozedur. Es ist nicht viel, nur etwas zum Üben.

Create Proc DisplayStudents
AS
BEGIN
     /*selecting all records from the table whose name is "Employee"*/
    Select * From Employee
END

Das ist meine Ansicht:

@model IEnumerable<MVCSimpleApp.Models.Employee>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
 }

 <h2>Student List</h2>

 <p>
    <a href="@Url.Action("Create")" title="Add new" class="btn btn-primary btn-lg">
        <span class="glyphicon glyphicon-plus "></span>
        Add Student
    </a>


</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.EmployeeId)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.FirstName)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.LastName)
        </th>
        <th></th>
    </tr>

 @foreach (var item in Model) {
 <tr>
    <td>
        @Html.DisplayFor(model => item.EmployeeId)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.FirstName)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.LastName)
    </td>
    <td>
        <span>
            <a href="@Url.Action("Edit", new { id = item.EmployeeId})" title="Edit Record">
                <span class="glyphicon glyphicon-pencil"></span>
            </a>
        </span>
        |
        <span>
            <a href="@Url.Action("Details", new { id = item.EmployeeId})" title="View Details">
                <span class="glyphicon glyphicon-th-list"></span>
            </a>
        </span>
        |
        <span>
            <a href="@Url.Action("Delete", new { id = item.EmployeeId})" title="Delete">
                <span class="glyphicon glyphicon-trash"></span>
            </a>
        </span>
    </td>
</tr>
}
  /*this is the button I want the stored procedure to be called on when I click it*/
  <button>Run</button>
</table>

Bitte Leute, ich brauche Eure Meinungen und Feedback zu dieser Angelegenheit. Akzeptiert Tipps zum Übergeben von Parametern an eine gespeicherte Prozedur. Bitte korrigieren Sie mich, wenn ich die Dinge nicht richtig mache. Dank für Ihr Interesse

Antworten auf die Frage(4)

Ihre Antwort auf die Frage