在 MVC 中,我知道我们可以从这样的 get 请求中获取参数:
要求:
http://www.example.com/method?param1=good¶m2=bad
并在 Controller 中
public ActionResult method(string param1, string param2)
{
....
}
但在我的情况下,外部网站向我发送了一个 get 请求,例如:
http://www.example.com/method?param.1=good¶m.2=bad
在 Controller 中,当我尝试满足此请求时,如下所示:
public ActionResult method(string param.1, string param.2)
{
....
}
由于变量名称中的点,我收到构建错误。我怎样才能得到这些参数?不幸的是,我不能要求他们更改参数名称。
最佳答案
使用以下代码:
public ActionResult method()
{
string param1 = this.Request.QueryString["param.1"];
string param2 = this.Request.QueryString["param.2"];
...
}
关于asp.net-mvc - MVC-如何从具有包含点字符的参数名称的获取请求中获取参数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21832610/