【问题标题】:How to close a view from controller after running ActionResult运行 ActionResult 后如何从控制器关闭视图
【发布时间】:2021-06-26 23:32:57
【问题描述】:

我是 MVC 和 JS 的新手。在控制器中运行 Action 后,我试图关闭一个弹出窗口。但是,我无法提出解决方案或找到可行的解决方案。这似乎是一个简单的问题,但它仍然是。我在here 和许多其他地方尝试了解决方案,但它不起作用。

ActionResult 控制器中的方法。这会收集弹出窗口上的所有数据。

[ActionName("NewStudentSchedule")]
[HttpPost]
public ActionResult NewStudentSchedule_Submit(Student student)
{
    return View();
}

单击“保存”按钮后窗口应关闭。

<input type="submit" class="btn btn-danger btn-lg" value="Save" /> 

任何帮助将不胜感激。

【问题讨论】:

  • 要关闭页面吗?然后建议的链接应该这样做

标签: c# asp.net-mvc-4


【解决方案1】:

您可以使用 from ajax call to call action 方法,然后执行您想要的任何任务。

同样的代码:

var finalParams = { Student : $('#Student').val() };
$.ajax({
                        url: "/ControllerName/NewStudentSchedule",
                        type: "POST",
                        dataType: 'json',
                        contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
                        data: finalParams 
                    }).done(function (result) {
                        // do something with the result now
                        if (result.status === "success") {
                            $('#ListSection').load("/Resume/EducationHistoryList");
                            
                            $("#sectionMustbeClose").hide();


                        } else {
                            alert(result.message);
                        }
                    });

【讨论】:

    猜你喜欢
    • 2019-05-30
    • 2012-01-28
    • 1970-01-01
    • 2021-06-17
    • 1970-01-01
    • 2011-06-11
    • 2020-02-17
    • 1970-01-01
    相关资源
    最近更新 更多