I am updating some features in a site which is made in asp.NET MVC. I am trying to show an alert when it successfully saves data or when it has some error while saving. My code is something like this:
---------Controller -----
public JsonResult Insert(string post)
{
var posted = Functions.SharePost(post)
if (posted == true)
{
return Json(new { message = "true" });
}
return Json(new { message = posted});
}
---- View code --------
@using (Ajax.BeginForm("Insert", "WebsitePosting", new AjaxOptions { HttpMethod = "POST", OnComplete = "CheckError(error);" }))
{
@Html.TextArea("post", new { data_val_required = "The field is required.", data_val = "true", style = "width:800px" })
<input type="submit" value="Save" class="k-button" />
}
----- Script ----
<script>
function CheckError(error)
{
if(error == "true"){alert("success");}
else{alert("faild");}
}
</script>
Can anyone tell me what I am doing wrong? Thanks in advance.
errorwill be an object that either contains a propertymessageor a propertysuccess. You need to check those properties