Iam Not expecting retuing result when i call the server, Iam just passing inputs to actionResult which will use it to create a new object and insert it to database using entityFramework.
<script>
$(document).ready(function () {
$("#Add").click(function () {
var EmployeeeId = $("#EmployeeId").val();
var Phone =$("#Phone").val();
var Email = $("#Email").val();
var Address = $("#Address").val();
var UserModel =
{
"EmployeeId": EmployeeeId,
"Phone": Phone,
"Address": Address,
"Email": Email
}; $.ajax({url: '@Url.Action("AddNewContactList","Home")',
type: "POST",
dataType: "json",
data: JSON.stringify(UserModel),
contentType: 'application/json; charset=utf-8',
success: function (result) {
//Doesnt Matter
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Failed");
}
And here is my Controller Code
And this is my controller action being called
[HttpPost]
public ActionResult AddNewContactList(ContactList c)
{DbContext m = new DbContext();
m.ContactList.Add(c);
m.SaveChanges();
retu View();
}
