私は新しいオブジェクトを作成するためにそれを使用するactionResultに入力を渡し、entityFrameworkを使用してそれをデータベースに挿入し、何も返さないようにします。戻り値を期待せずにサーバーにajax呼び出しを送信する方法
$(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");
}
そして、ここでは私のコントローラコードでコントローラのアクションが
[HttpPost]
public ActionResult AddNewContactList(ContactList c)
{
DbContext m = new DbContext();
m.ContactList.Add(c);
m.SaveChanges();
return View();
}
あなたのタイトルには、結果が期待できないと言われています。あなたの質問の最初の行は、あなたがいると言います。どちらですか? – Jamiec
あなたは何をしたいですか? –
ただ応答を無視する...または何も返さないようにサーバー上のメソッドを変更します。 – epascarello