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()
}