In MVC code we have views and actions associated with it.
For doing that , we need to use the button and the form tag to be of POST type or the GET type.
For invoking action from the button which is not of submit type you need to provide the name of the action to be invoked and if you have same action name for the different controllers then you need to provide the action name with controller.
@model IEnumerable<MVC_Demo.Models.EmployeeModel>
@{
ViewBag.Title = "Index";
}
@{ var i = 1;}
@using (Html.BeginForm("Edit", "RegisterGrid", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.EmpId)
</th>
<th>
@Html.DisplayNameFor(model => model.FirstName)
</th>
<th>
@Html.DisplayNameFor(model => model.MiddleName)
</th>
<th>
@Html.DisplayNameFor(model => model.LastName)
</th>
<th>
@Html.DisplayNameFor(model => model.PhoneNo)
</th>
<th>
@Html.DisplayNameFor(model => model.Address)
</th>
<th>
Action
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.Label("", Convert.ToString(item.EmpId), new { id = "lblEmpId" + i })
</td>
<td>
@Html.Label("", item.FirstName, new { id = "lblFirstName" + i })
</td>
<td>
@Html.Label("", item.MiddleName, new { id = "lblMiddleName" + i })
</td>
<td>
@Html.Label("", item.LastName, new { id = "lblLastName" + i })
</td>
<td>
@Html.Label("", item.PhoneNo, new { id = "lblPhoneNo" + i })
</td>
<td>
@Html.Label("", item.Address, new { id = "lblAddress" + i })
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id =item.EmpId, @class = "editLink" }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
i = i + 1;
}
</table>
}
Here we have passed the name of the action in the button which is of edit type.
0 Comment(s)