Evil rising
Evil rising

Reputation: 442

Crud in WebGrid

how to put delete, update, edit buttons into MVC webGrid ?

code:

<div>

@{

    var grid = new WebGrid(ViewData.Model, defaultSort: "EmplID");

}

@grid.GetHtml()

</div>

controller:

public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Precise Technology Consultants";
            var DataContext = new EmployeeAtdDataContext();
            //var EmployeeAtd = DataContext.GetAttendance_Sp();
            IEnumerable<GetAttendance_SpResult> EmployeeAtd = DataContext.GetAttendance_Sp().ToList();
            return View(EmployeeAtd);
        }

now i am trying to put ADD, Delete, buttons in it ?

Upvotes: 0

Views: 818

Answers (1)

sean
sean

Reputation: 1205

I think you are looking for something like this:

@grid.GetHtml(columns: new [] {
    grid.Column("col1"),
    grid.Column("col2"),
    grid.Column(
       "",
        header: "Actions",
        format: @<text>
                @Html.ActionLink("Edit",   "Edit",   new { EmplID=item.EmplID} )
                |
                @Html.ActionLink("Delete", "Delete", new { EmplID=item.EmplID} )
               </text>
    )
})

Where the controller contains methods like:

public ActionResult Edit(int EmplID)
...

Upvotes: 1

Related Questions