【发布时间】:2014-02-27 06:41:04
【问题描述】:
我正在尝试将实体保存为编辑模式。 我想使用 FormCollection 将值从 View 传递到控制器,但没有值进入控制器。
这里是标记:
@using (Html.BeginForm("Edit", "Product", FormMethod.Post, new { enctype = "multipart/form-data", id = "frmCreate" }))
{
<div class =" row-fluid Span12" style ="margin-bottom :15px">
<div class="span6" >
<div class ="span4">
<label>Product Name</label>
</div>
<div class ="span6">
<input type="text" value="@ViewBag.Name" id="ProductName" name="ProductName" style="height:20px; width:100%;" />
</div>
</div>
<div class="span6" >
<div class="span4" >
<label > Product Code</label>
</div>
<div class="span6" >
<input type="text" value="@ViewBag.SectionCode" id="SectionCode"/>
</div>
</div>
<div class="span11" style="text-align:right">
<input class="btn btn-primary" type="submit" value="Save" id="Edit"/>
<button class="btn btn-default">Cancel</button>
</div>
}
这是我的控制器代码
[HttpPost]
public ActionResult Edit(FormCollection form)
{
Product product = new Product();
product.SectionCode = Convert.ToString(form["SectionCode"]);
product.Name = Convert.ToString(form["Name"]);
return RedirectToAction("SaveData", oProductNew);
}
没有值进入 FormCollection。
【问题讨论】:
-
我在你的 html 源代码中没有看到任何形式,也没有它的 html 助手。你如何声明表单并使用 post 制作它?
-
你有什么理由使用
FormCollection? -
您的 SectionCode 输入字段没有名称。
-
我想,我忘了把名字放在标签里...我认为 id 就足够了...
标签: c# asp.net-mvc-4 http-post formcollection