【发布时间】:2015-06-09 19:43:15
【问题描述】:
我的 cshtml 页面有这样的代码
model Kouponer.Models.person_T
@using (Html.BeginForm("BuynowForm", "Home"))
{
<label>@Model.name</label>
<label>address</label>
@Html.TextBox("address")<div>
<input type="submit" value="Submit" class="btn btn-primary" />
}
而我目前的actionresult方法是
[HttpPost]
public ActionResult BuynowForm(FormCollection col)
{ string address = col["address"];
return View();
}
在这里,我将只获得 formcollection 值。如何传递模型 表单集合?
【问题讨论】:
-
Please read this link 基本上,你不应该使用 FormCollection
-
@br4d,请解释一下为什么永远不要使用 FormCollection?是否存在性能问题或其他问题?
-
@br4d,感谢您的信息
-
@br4d 有一次我喜欢使用 FormCollection。当我想要一个 Get 和 Post 方法,但我不需要任何参数时......将 FormCollection 作为 post 的参数可以解决该问题。当然,在这种情况下,我实际上并没有使用它......它只是为了确保我不会因为具有重复的方法签名而出现编译错误。