简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM