首页 > 解决方案 > 即使操作中没有错误,asp.net core 也会抛出 500

问题描述

我不确定如何解决 asp.net core 2.2 操作将 HTTP 500 返回到浏览器的场景,即使它应该返回一个匹配的视图,即使它一直完成操作到返回视图() 陈述。

这是浏览器中的代码,尽管返回了视图,但我从操作中获得了 500 的内部 POST。

$.post({
            url: '/Analysis/SomeOtherAction',
            contentType: dataType,
            data: JSON.stringify(data),
            success: function (response) {
                if (response.IsValid) {
                    if (evaluation === "1") {
                        $.post({
                            url: '/Analysis/WhyDoesThisFail',
                            contentType: dataType,
                            data: JSON.stringify(data)
                        });
                    }
                    else {
                        window.location = '/Results/Download?fileGuid=' + response.Data.FileGuid
                            + '&filename=' + response.Data.FileName;
                    }
                }
                else {
                    $('#validationList').empty();
                    for (var i = 0; i < response.ValidationMessages.length; i++) {
                        $("#validationList").append("<li>" + response.ValidationMessages[i] + "</li>");
                    }
                    $('#modelValidationModal').modal('toggle');
                }
            }
        });

在我的控制器中,我有:

[HttpPost]
public IActionResult WhyDoesThisFail([FromBody] SomeViewModel model)
{
    // some stuff happens in here...

    return View(); // I can step through all the way to this point with no errors
}

我想返回位于视图下分析文件夹中的WhyDoesTHisFail 视图。

标签: asp.net-mvcasp.net-core

解决方案


推荐阅读