Bha*_*ran 6 asp.net-mvc asp.net-mvc-5
我有这样的代码的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" />
}
Run Code Online (Sandbox Code Playgroud)
我目前的actionresult方法是
[HttpPost]
public ActionResult BuynowForm(FormCollection col)
{ string address = col["address"];
return View();
}
Run Code Online (Sandbox Code Playgroud)
在这里,我将仅获取formcollection值。如何将模型与formcollection一起传递?
除非我完全遗漏了某些内容,否则您应该只需在控制器的签名上添加模型类型即可。
[HttpPost]
public ActionResult BuynowForm(Models.person_T model, FormCollection col)
{ string address = col["address"];
string addressFromModel = model.Address;
return View();
}
Run Code Online (Sandbox Code Playgroud)
但是,如果要使用模型绑定,则需要 FormCollection 对象似乎是多余的。我会阅读评论中给出的链接,然后使用模型绑定。
| 归档时间: |
|
| 查看次数: |
12950 次 |
| 最近记录: |