如何在动作方法ASP.NET mvc中访问我的formcollection?

mic*_*ael 14 asp.net-mvc

我有动作方法访问的表单集合,但如何获取它的值.我试过这样

string value = collection[1];
Run Code Online (Sandbox Code Playgroud)

但我没有得到这个值.我如何在action方法中访问该值.

Ger*_*ndo 29

如果你有:

<input type="text" name="inputName" />
Run Code Online (Sandbox Code Playgroud)

您可以使用元素的属性名称,如下所示:

[HttpPost]
public ActionResult yourAction(FormCollection collection)
{
     string value = Convert.ToString(collection["inputName"]);
     ...
     return View();
}    
Run Code Online (Sandbox Code Playgroud)


ipr*_*101 1

类似(代码未测试)-

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddNewLink(FormCollection collection)
{
    string url = collection[1].ToString();
}
Run Code Online (Sandbox Code Playgroud)