ASP.NET MVC:RedirectToAction与参数POST操作 [英] ASP.NET MVC: RedirectToAction with parameters to POST Action

查看:504
本文介绍了ASP.NET MVC:RedirectToAction与参数POST操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经被问这里:

RedirectToAction与参数

但是,如果我有同名但不同参数的两个动作?我如何重定向到POST 条款的行动,而不是GET 条款操作。

 公众的ActionResult条款(){
    // get方法
}[HttpPost]
公众的ActionResult条款(串月,串一年,INT存款= 0,INT总= 0){
    //处理POST请求
}


解决方案

算了家伙,其实我可以调用该方法直接而不是使用 RedirectToAction 像这样:

 收益条款(年,月,金,总数);

而不是:

 返回RedirectToAction(条款,{月,年,存款,总});

This question has been asked here:

RedirectToAction with parameter

But what if I have two actions with the same name but different parameters? How do I redirect to the POST Terms action instead of the GET Terms action.

public ActionResult Terms() {
    //get method
}

[HttpPost]
public ActionResult Terms(string month, string year, int deposit = 0, int total = 0) {
    //process POST request
}

解决方案

Nevermind guys, actually I could just call the method directly instead of using RedirectToAction like so:

return Terms(month, year, deposit, total);

Instead of:

return RedirectToAction("Terms", {month, year, deposit, total});

这篇关于ASP.NET MVC:RedirectToAction与参数POST操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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