I have a panel within a form that has 3 buttons save, edit and cancel.
When the user clicks on edit, the labels inside the panel change to textboxes wherein the user can edit the content. This part is done.
Now if the user has edited the content, but does not wish to save it, he clicks on cancel. When he does so, the edited text will be replace with the original content of the labels(data comes from the model).
I have followed the accepted answer given here
Controller:
[HttpPost]
public ActionResult Submit(int id, string actionType)
{
var model = new CustomerDetailsViewModel();
var custid = db.Customers.Find(id);
if(actionType == "Cancel")
{
model.Company = custid.Company;
model.Address = custid.Address;
model.FullName = custid.FirstName + " " + custid.LastName;
model.EMail = custid.EMail;
model.Phone = custid.Phone;
model.EntryDate = custid.EntryDate;
model.LastInterestShown = custid.LastInterestShown;
model.ID = custid.ID;
model.Status = custid.Status;
}
return PartialView(model);
}
View:
<input type="submit" value="Cancel" id="btncancel" name="actionType" class="btn btn-default" />
JS:
$("#btnCancel").click(function(e){
e.preventDefault();
$.ajax({
url: '/Client/Submit',
type: 'POST',
async: false
});
});
Can someone tell me where am I going wrong?