欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C# MVC获取表单(form)键值对

程序员文章站 2022-03-04 13:17:03
...

KeyValue存储

[HttpPost]
public ActionResult Index(FormCollection collection)
{
        Dictionary<string, string> nameValue = new Dictionary<string, string>();
    for (int i = 0; i < collection.Keys.Count; i++)
    {   
        nameValue.Add(collection.GetKey(i),collection.Get(i));
    }
}

数组存储

[HttpPost]
public ActionResult Index(FormCollection collection)
{
    List<string> message = new List<string>();
    for (int i = 0; i < collection.Keys.Count; i++)
    {
        message.Add(collection.GetKey(i) + ":"+collection.Get(i));
    }
    string[] nameValue = message.ToArray()
}
相关标签: mvc 表单 c#