我正在处理一个MVC项目,我希望传递一个填充了表单数据的FormCollection,并将其发布到我的控制器中的操作方法中。下面是该视图的一个示例:
<asp:TextBox ID="txtClientLastName" name="txtClientLastName" runat="server" class="focus"/>(是的,我知道!MVC视图中的ASP控件不是很好,但这就是我所拥有的。在视图中的标记之间也有后端代码,这就是为什么我没有替换它们的原因)
我使用帮助器链接到我的操作:
<%=Html.ActionLink("Save","ClientInformationEdit",new {id=Model.PersonId})%它调用了我的操作:
public ActionResult ClientInformationEdit(int id, FormCollection form)
{
//rptLOA_GridCommands(form, id);
CIHelper ch = new CIHelper();
ch.person.LastName = form["txtClientLastName"];
db.SaveChanges();
return View(ch);
}我的passes the correct value but FormCollection form is null so form["txtClientLastName"] is null and I don不知道为什么。
发布于 2013-05-28 01:46:07
添加如下post属性:
[HttpPost]
public ActionResult ClientInformationEdit(int id, FormCollection form)
{
//rptLOA_GridCommands(form, id);
CIHelper ch = new CIHelper();
ch.person.LastName = form["txtClientLastName"];
db.SaveChanges();
return View(ch);
}如果你想在点击超链接时发布表单,那么添加以下代码:
<%=Html.ActionLink("Save","ClientInformationEdit",new {id=Model.PersonId,onclick="document.getElementById('form-id').submit();"})%>发布于 2013-05-28 01:55:21
试试这个:
@using (Html.BeginForm("Save", "ClientInformationEdit", FormMethod.Post))
{
<input type="hidden" value="@Model.PersonId"/>
<asp:TextBox ID="txtClientLastName" name="txtClientLastName" runat="server" class="focus"/>
<input type ="submit"/>
}在您的视图中
https://stackoverflow.com/questions/16778095
复制相似问题