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

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

问题描述

此问题已在此处提出:

RedirectToAction 带参数

但是如果我有两个名称相同但参数不同的操作怎么办?如何重定向到 POST Terms 操作而不是 GET Terms 操作.

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
}

推荐答案

不用了,伙计们,实际上我可以直接调用方法而不是像这样使用 RedirectToAction :

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

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

代替:

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

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

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