控制器发布返回视图但不显示视图

时间:2015-03-04 06:21:35

标签: asp.net asp.net-mvc

我在 ViewController 中有一个 View.cshtml 文件,该文件有一个超链接。点击链接后,我调用ajax请求POST到 GreetingController 操作:

[HttpPost]
public async Task<ActionResult> Welcome(MyModel model)
{
    ActionResult result = null;
    Task<bool> createTask = Helper.Create(model);
    try
    {
        bool success = await createTask;
        if (success)
        {
            result = View();
        }
        else
            result = new HttpNotFoundResult("Specified resource was not found.");
    }
    catch
    {
        result = View("Error");
    }
    return result;
}

如果POST中的方法成功,我将结果设置为View属性。我有一个 Welcome.cshtml 视图,我希望它可以显示,但它并没有。我没有返回View,而是尝试返回RedirectToAction并创建了欢迎操作的GET版本,但它仍然没有显示。有人可以解释我做错了吗?

修改

AJAX电话:

$.ajax({
    type: "POST",
    url: "/greeting/welcome",
    data: JSON.stringify(model),
    dataType: "json",
    contentType: 'application/json; charset=utf-8',
    success: function (result) {
    },
    error: function (xhr, err) {
    }
});

此外,上面的回复最初是&#34;返回View()&#34;。我已将其更改为&#34;返回结果&#34;。

0 个答案:

没有答案