Deepak Deepak - 1 year ago 69
jQuery Question

JSON Doesn't perform the edit action in MVC

public PartialViewResult MemberEdit(Int32 MemID) // Update PartialView
MemberTbl Mem = db.MemberTbls.Where(x => x.ID == MemID).FirstOrDefault();
MemberTbl MemInfo = new MemberTbl();

MemInfo.ID = Mem.ID;
MemInfo.Name = Mem.Name;
MemInfo.Post = Mem.Post;
MemInfo.Phone = Mem.Phone;

return PartialView(MemInfo);

public JsonResult MemberEdit(GarhwalBhawan.Models.MemberTbl MemID) // Record Update

MemberTbl MemDt = db.MemberTbls.Where(x => x.ID == MemID.ID).FirstOrDefault();

if (ModelState.IsValid)
MemDt.Name = MemID.Name;
MemDt.Post = MemID.Post;
MemDt.Phone = MemID.Phone;
myMessage = "Success";

myMessage = "Failed";
return Json(myMessage, JsonRequestBehavior.AllowGet);

I've the above ActionResult in My Controller. Now I want to save the field with JSON with help of ID.
I've created the following JQuery method on the click of that button.

$(document).ready(function () {
$('#memberSave').click(function () {
var Name = $("#Name").val();
var Post = $("#Post").val();
var Phone = $("#Phone").val();

var Member = {
"Name": Name, "Post": Post,
"Phone": Phone
$.post("/Admin/MemberEdit", Member,
function (data) {
if (data == "Success") {
window.location.href = 'MemberView';
else if (data == "Failed") {
alert('Cannot Save!! Please Fill all Details or Contact Support')

else {
}, 'json');


Thus I've created a button:-
<input id="memberSave" type="button" value="Save Changes" />

But on click this button is showing error:-
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
And Getting me the alert :-
alert('Cannot Save!! Please Fill all Details or Contact Support').

Please Help.

Ray Ray
Answer Source

You did not put the parameter “ID” into your parameter “Member”

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download