尝试使用Javascript AJAX调用控制器操作时,我收到500个内部服务器错误。
当用户单击确认按钮时,我想调用一个控制器方法。
CS控制器
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(string idFb, FormCollection from)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(urlAPISignature);
var deleteTask = client.DeleteAsync("api/whitepages/" + idFb);
deleteTask.Wait();
var result = deleteTask.Result;
if (result.IsSuccessStatusCode)
{
return RedirectToAction("Index");
}
return RedirectToAction("Index");
}
}
CSHTML文件
columns.Add().Encoded(false).Sanitized(false).Titled("").Filterable(false).RenderValueAs(model =>
"<img title=\"supprimer\" class=\"delBtnWp\" data-idEpi=\"" + model.IdFb + "\" src=\"" + @Url.Content("~/Content/Images/trash-can.png") + "\" height=\"24\" width=\"24\" alt=\"del\" />");
.
.
.
.
<script>
$(".delBtnWp").click(function () {
var idFb = $(this).attr("data-IdFb");
bootbox.dialog({
title: 'Confirmer la suppression',
message: 'Souhaitez-vous vraiment supprimer la ligne ?',
buttons: {
danger: {
label: 'Non'
},
success: {
label: 'Oui',
className: "btn-success",
callback: function () {
success ();
}
}
},
callback: function (result) {
if (result) {
$.ajax({
type: 'POST',
url: "@Url.Action("Delete", "WhitePages")",
data: { IdFb: idFb },
success: function (data) {
alert("Yes");
}
});
}
}
});
});
</script>
编译器甚至没有达到控制器的作用。
答案 0 :(得分:0)
关于您的情况,请从Controller中的ActionMethod中删除syntax = "proto3";
package ngage.sdk.distributedmemory.config;
import "scalapb/scalapb.proto";
import "pboptions.proto";
import "google/protobuf/duration.proto";
import "ngage.sdk.configs.Config"; //this became red
option (scalapb.options) = {
flat_package: true
single_file: true
};
message ShardMemoryConfig {
option (ngage.type_id) = 791;
int32 size = 1;
oneof config { //everything inside oneof is red
ngage.sdk.configs.RedisConfig redis = 100002;
ngage.sdk.configs.ElasticConfig elastic = 100003;
ngage.sdk.configs.S3Config s3 = 100004;
}
}
,或在View上生成伪造令牌,然后在AJAX调用中发送它。另外,您需要将[ValidateAntiForgeryToken]
更改为data-idEpi
。这样可以解决您的500 Internal Server Error。