gpt4 book ai didi

c# - 将值从 Controller 发送到 Jquery

转载 作者:行者123 更新时间:2023-11-30 17:26:15 26 4
gpt4 key购买 nike

我有一个 MVC 应用程序。

Controller :

public ActionResult DescargaCsv()
{
// do stuff
if (status != 0){
return value to javascript and display an alert there
}
else{
//do other stuff, this is OK
}
}

JavaScript:

function fnDownloadExcel() {
$.ajax({
url: fnDownloadExcel?idArchivo=" + $("#idArchivo").val(),
type: "POST",
success: function (data) {
$("#idMessage").val(data[0]);
if (data[0] == "R") {
alert("Status: " + $("#idMensaje").val());
}
else {
//do other stuff
}
}
});

如何将我在 Controller 中获得的“状态”值发送到 javascript?

最佳答案

C#

public ActionResult DescargaCsv() {  
// do stuff
if (status != 0){
return new HttpStatusCodeResult(500, "This is a bad status message");
} else{
//do other stuff, this is OK
}
}

j查询

function fnDownloadExcel() {
$.ajax({
url: fnDownloadExcel?idArchivo=" + $("#idArchivo").val(),
type: "POST",
success: function (data) {
$("#idMessage").val(data[0]);
if (data[0] == "R") {
alert("Status: " + $("#idMensaje").val());
} else {
//do other stuff
}
},
statusCode: {
500: function(data) {
alert(data);
}
}
});
}

这是未经测试的,但它应该有效。

关于c# - 将值从 Controller 发送到 Jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24195463/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com