asp.net mvc期间的POST参数

Rod*_*son 1 c# facebook asp.net-mvc-2

我知道你可以在querystring参数中有一个句点,但你不能在.net中的变量名中指定一个句点.

以下代码显然不起作用,但我的外部系统使用名称中的句点.有没有办法做到这一点?

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(string hub.mode)
{
    return View();
}
Run Code Online (Sandbox Code Playgroud)

Dar*_*rov 5

您可以直接从Request哈希中读取值:

[HttpPost]
public ActionResult Index()
{
    string hubMode = Request["hub.mode"];
    return View();
}
Run Code Online (Sandbox Code Playgroud)

或使用中介课:

public class Hub
{
    public string Mode { get; set; }
}

[HttpPost]
public ActionResult Index(Hub hub)
{
    string hubMode = hub.Mode;
    return View();
}
Run Code Online (Sandbox Code Playgroud)

您会注意到.ASP.NET MVC默认模型绑定器具有特殊含义.