我正在開發一個點網核心 MVC 應用程式。我的控制器具有以下功能:
[HttpPost]
public JsonResult Delete(string chkId)
{
if (chkId == "" || chkId == null)
StatusCode(StatusCodes.Status500InternalServerError);
List<string> stringList = new List<string>();
try
{
stringList = chkId.ToString().Split(',').ToList();
for (var i = 0; i < stringList.Count(); i )
{
StringDA.Delete(Convert.ToInt64(stringList[i]), GetString());
}
string result = "Success";
return Json(result, new Newtonsoft.Json.JsonSerializerSettings());
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
現在我的視圖正在嘗試使用以下 jquery 訪問該函式。
$('#btnDelete').on('click', function () {
// Code.........
var msg = "Are you sure you want to delete?";
var check = confirm(msg);
//alert(chkVal);
if (check == true) {
var join_selected_values = chkVal.join(",");
$.ajax({
url: "/General/Delete",
type: "POST",
cache: false,
dataType: 'json',
data: 'chkId=' join_selected_values,
success: function (response) {
//alert(response.result);
if (response.result == "Success") {
alert("Record(s) deleted");
..........
}
else {
alert("Error in Appication");
}
}
});
}
}
});
但是當我測驗我的應用程式response.resrult總是拋出“未定義”,即使控制器功能是好的。當我明確將其宣告為“成功”時,我無法理解為什么 response.resrult 未定義?
uj5u.com熱心網友回復:
你應該定義結果變數
return new JsonResult( new { result="Sucess" } );
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/438181.html
上一篇:使用反應鉤子更改嵌套介面的值
下一篇:Python中json字串的操作
