执行提交(回发),并与ASP.net MVC重定向 [英] performing submit(postback) and redirect with ASP.net MVC

查看:113
本文介绍了执行提交(回发),并与ASP.net MVC重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用提交从我的标记,一个ASP.net MVC的行动。

I want to use submit from my markup, to an ASP.net MVC action.

然后我要请求重定向到另一个网址。

Then I want to redirect the request to another url.

我可以这样做呢? ?还是MVC只对应阿贾克斯

Can I do so? Or MVC corresponding to ajax only?

推荐答案

如果您使用的 Html.BeginForm 像这样:

<% using(Html.BeginForm("HandleForm", "Home")) { %>
    <fieldset>
        <legend>Fields</legend>
        <p>
            <%= Html.TextBoxFor(m => m.Field1) %>
        </p>
        <p>
            <%= Html.TextBoxFor(m => m.Field2) %>
        </p>
        <p>
            <input type="submit" value="Submit" />
        </p> 
    </fieldset>
<% } %>



那么你的控制器动作可以执行重定向:

Then your controller action can perform a redirect:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult HandleForm(MyModel myModel)
{
    // Do whatever you need to here.

    return RedirectToAction("OtherAction", myModel);
}

public ActionResult OtherAction(MyModel myModel)
{
    return View(myModel);    
}



编辑::上面的例子现在将结合用下面的模型,并且可以操作之间进行传递:

: The above example will now bind with the following model and can be passed between actions:

public class MyModel
{
    public string Field1 { get; set; }
    public string Field1 { get; set; }
}

这篇关于执行提交(回发),并与ASP.net MVC重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆