Hi
In Controller how i can track whether it is Update or Add
<body>
<div class="table-title">
<div class="row">
<div class="col-sm-6">
</div>
<div class="col-sm-6 text-right">
<button type="button" class="btn btn-primary" data-target="#myModal" data-toggle="modal" float-right onclick="clearTextBox();"> <i class="fa fa-plus"></i> Add New Location</button><br /><br />
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-body">
<table class="table table-striped table-hover" id="tblProduct">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>
<th>
@Html.DisplayNameFor(model => model.IsActive)
</th>
<th>Action</th>
</tr>
</thead>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.IsActive)
</td>
<td>
<a class='btn btn-primary btn-sm' id='btnEdit' data-target="#myModal" data-toggle="modal"><i class='fa fa-pencil'></i> Edit </a>
@if (item.IsActive)
{
<a id="btnDelete" class="btn btn-danger btn-sm" data-target="#DeleteModal" data-toggle="modal"
data-path="@Url.Action("Delete", "Location", new { id = @item.Id })" style='margin-left:5px'><i class='fa fa-trash'></i> Delete </a>
}
else
{
<a class='btn btn-danger btn-sm disabled' id='btnDelete' style='margin-left:5px'><i class='fa fa-trash'></i> Delete </a>
}
</td>
</tr>
}
</table>
</div>
</div>
</div>
</div>
@using (Html.BeginForm("CreateEdit", "Location", FormMethod.Post))
{
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
</div>
<div class="modal-body">
<div class="form-group row">
<label for="Id" class="col-sm-2 col-form-label">Id</label>
<div class="col-sm-10">
<input type="Text" class="form-control" id="txtId" Name="Id" placeholder="Product Id">
</div>
</div>
<div class="form-group row">
<label for="Description" class="col-sm-2 col-form-label">Description</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="txtDescription" Name="Description" placeholder="Description">
</div>
</div>
<div class="form-group row">
<label for="IsActive" class="col-sm-2 col-form-label">IsActive</label>
<div class="form-check col-sm-10">
<input class="form-check-input" type="checkbox" value="" id="IsActive" name="IsActive">
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
}
</body>
**********************************************
[HttpPost]
public ActionResult CreateEdit(Location objLocation)
{
if (ModelState.IsValid)
{
dbLocation.Add(objLocation);
//return Json(new { success = true, message = "Successfully Saved" });
}
return RedirectToAction("Index");
}
Thanks