【问题标题】:redirect to POST with javascript in asp.net mvc在 asp.net mvc 中使用 javascript 重定向到 POST
【发布时间】:2011-05-13 12:47:42
【问题描述】:

我有 2 个控制器方法:

[HttpGet]
public ActionResult SomeAction(SomeModel model, string someString)
{
//..
return View()

[HttpPost]
public ActionResult SomeAction(SomeModel model)

我正在尝试找到一种方法,可以让我从控制器(其他一些控制器)直接导航到 Post 方法。我听说这是一种在 javascript 中执行此操作的方法,但我无法在任何地方找到它。这个想法是在模型中设置一个字段,并在视图的开头检查它 - 如果它已设置,则执行 javascript 操作以立即重定向到控制器中的 Post 操作。如果有人知道怎么做,我会很感激它

【问题讨论】:

    标签: javascript asp.net-mvc http-post


    【解决方案1】:

    听起来您想在页面加载时检查表单是否已填写,如果已填写,请立即将其发布到适当的操作?

    如果是这样

    $(function() {
        if () { // determine here if the form has been filled out and completed
            $('#theform').submit(); // this posts the form, which will hit the post action
        }
    });
    

    【讨论】:

    • 问题是我对 javascript 了解不多,所以我没有设法让你的代码工作,但我使用了一些 jquery,现在它似乎工作了 $.post('Controller/Action', function (数据) { });
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    • 2011-12-30
    • 2016-10-06
    • 2021-05-24
    • 1970-01-01
    相关资源
    最近更新 更多