我正在尝试以编辑模式保存实体。我想使用 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。