开发者

asp.net mvc period in POST parameter

i konw that you can have a period in a querystring parameter, but you cant specify a period in variable names开发者_开发问答 in .net.

The following code obviously does not work, but my external system uses the period in the names. Is there a way to do this?

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(string hub.mode)
{
    return View();
}


You could read the value directly from the Request hash:

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

or using an intermediary class:

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

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

As you will notice . has special meaning for the ASP.NET MVC default model binder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜