MVC-如何从具有参数名称,其中包括点的字符的GET请求参数值 [英] MVC- How to get parameter value from get request which has parameter names including dot characters

查看:130
本文介绍了MVC-如何从具有参数名称,其中包括点的字符的GET请求参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MVC中,我知道我们可以得到这样的GET请求参数:

In MVC, I know we can get parameters from a get request like this:

请求:

http://www.example.com/method?param1=good&param2=bad

和控制器中

public ActionResult method(string param1, string param2)
{
   ....
}

但在我的处境外部网站给我发送GET请求,如:

But in my situation an external website sends me a get request like:

http://www.example.com/method?param.1=good&param.2=bad

和控制器中时,我尽量满足这样的要求如下:

And in controller when i try to meet this request like as follow:

public ActionResult method(string param.1, string param.2)
{
   ....
}

我得到建立,因为变量名点的误差。我怎样才能得到这些参数?遗憾的是我不能要求他们改变的参数名称。

I get build errors because of dot in variable name. How can i get these parameters ? Unfortunately i can not ask them to change parameter names.

推荐答案

使用以下code:

    public ActionResult method()
    {
        string param1 = this.Request.QueryString["param.1"];
        string param2 = this.Request.QueryString["param.2"];

        ...
    }

这篇关于MVC-如何从具有参数名称,其中包括点的字符的GET请求参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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