如何路由在ASP.Net MVC 3遗留查询字符串参数? [英] How to route legacy QueryString parameters in ASP.Net MVC 3?

查看:180
本文介绍了如何路由在ASP.Net MVC 3遗留查询字符串参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是第三方服务,做一个异步回调,我提供给他们一个网址。
所以我告诉他们使用 http://www.mysite.com/Status/Incoming
这显然​​必须映射到我的StatusController来电()方法。

I am using a third party service that does an async callback to a URL I provide to them. So I tell them to use http://www.mysite.com/Status/Incoming. This must obviously map to an Incoming() method on my StatusController.

不过,我没有控制权是他们叫我的网址与参数的格式。
例如。他们会做一个回调,如:的http://www.mysite.com/Status/Incoming?param1=val1&param2=val2&param3=val3

However, what I don't have control over is the format of the parameters they call my URL with. E.g. They will do a callback such as: http://www.mysite.com/Status/Incoming?param1=val1&param2=val2&param3=val3

我想这个映射到我的行动方法的参数:接收(字符串参数1,字符串参数2,INT参数3)

I want to map this to the parameters of my action method: Incoming(string param1, string param2, int param3)

我如何做到这一点?

我已经找到了很多关于自定义路由的东西,但没有任何有关传统查询字符串参数。

I have found a lot of stuff about custom routing, but nothing about legacy QueryString parameters.

推荐答案

有作为的传统的查询字符串参数没有这样的事的。有查询字符串参数,它们是HTTP规范的一部分。并假设 http://www.mysite.com/Status/Incoming?param1=val1&param2=val2&param3=val3 URL是叫你不需要任何途径,使其映射到了以下行动(默认路由会做得很好):

There is no such thing as legacy query string parameters. There are query string parameters and they are part of the HTTP specification. And assuming that the http://www.mysite.com/Status/Incoming?param1=val1&param2=val2&param3=val3 url is called you don't need any route to make it map to the following action (the default route will do just fine):

public ActionResult Incoming(string param1, string param2, string param3)
{
    ...
}

默认的模型将结合这些值照顾。

The default model will take care of binding those values.

这篇关于如何路由在ASP.Net MVC 3遗留查询字符串参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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