Database Field Name:
- empid int pk auto increment
- empname varchar(50)
- empsalary varchar(50)
- empage int
I want to open a bootstrap model when user click on edit button then open the edit view see my console logs:
plzz help ?
I create an edit partial view see code
Code:
HomeController.cs
- public class HomeController : Controller
- {
- empEntities _dbcontext = new empEntities();
- public ActionResult Index()
- {
- return View(_dbcontext.empls.ToList());
- }
- public ActionResult Edit(int empid)
- {
- var id = _dbcontext.empls.Find(empid);
- return View();
- }
- [HttpPost]
- public ActionResult Edit(empl empobj)
- {
- var recordfind = _dbcontext.empls.Find(empobj.empid);
- recordfind.empname = empobj.empname;
- recordfind.empsalary = empobj.empsalary;
- recordfind.empage = empobj.empage;
- _dbcontext.SaveChanges();
- return View();
- }
- }
Index.cshtml
- @model IEnumerable
- "~/Content/PagedList.css" rel="stylesheet" type="text/css" />
- @{
- ViewBag.Title = "Index";
- }
Index
- @Html.ActionLink("Create New", "Create")
class="table">
- @Html.DisplayNameFor(model => model.empname)
- @Html.DisplayNameFor(model => model.empsalary)
- @Html.DisplayNameFor(model => model.empage)
- @foreach (var item in Model)
- {
- @Html.DisplayFor(modelItem => item.empname)
- @Html.DisplayFor(modelItem => item.empsalary)
- @Html.DisplayFor(modelItem => item.empage)
- ="btn btn-primary " id="btn-edit-employ" data-id="@item.empid">Edit
- @Html.ActionLink("Details", "Details", new { id = item.empid }) |
- @Html.ActionLink("Delete", "Delete", new { id = item.empid })
- }
- //edit view is a partial view
Edit.cshtml
- @model DatabasefirstApproach.empl
- @using (Html.BeginForm())
- {
- @Html.AntiForgeryToken()
- class="form-horizontal"*@ class="modal fade" id="mod-edit-emp">
empl
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- @Html.HiddenFor(model => model.empid)
class="form-group">- @Html.LabelFor(model => model.empname, htmlAttributes: new { @class = "control-label col-md-2" })
class="col-md-10">- @Html.EditorFor(model => model.empname, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.empname, "", new { @class = "text-danger" })
class="form-group">- @Html.LabelFor(model => model.empsalary, htmlAttributes: new { @class = "control-label col-md-2" })
class="col-md-10">- @Html.EditorFor(model => model.empsalary, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.empsalary, "", new { @class = "text-danger" })
class="form-group">- @Html.LabelFor(model => model.empage, htmlAttributes: new { @class = "control-label col-md-2" })
class="col-md-10">- @Html.EditorFor(model => model.empage, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => model.empage, "", new { @class = "text-danger" })
class="form-group">class="col-md-offset-2 col-md-10">- "submit" value="Save" class="btn btn-default" />
- }
- @Html.ActionLink("Back to List", "Index")
I want to open the BootStrap Model When the user click on the edit button??
My empid is fetch when I click on Edit Button but my Edit view is Not open??
Edit view is a partial view. empid is fetched when I click on edit button but my edit partial view is not open ??
see browser logs:
How to open edit view when click on the edit button?
plz help??
Gowtham RamarPosted Feb 2, 2020, 8:34 PM