我无法弄清楚为什么我无法检索表单数据。在下面提供的工作中,添加了视图,viewmodel和控制器。请让我知道是否需要其他信息:
namespace Chargebacks.app.ViewModels
{
public class ChargebackViewModel
{
public List<Fault> _TheFaults;
public List<ChargebackStatu> _TheChargebackStatus;
public List<Responsible> _TheResponsibleForChargeback;
public List<Department> _TheDepartments;
public GetChargeback_Result _TheCustomerChargeback;
}
}
@using (Html.BeginForm("Save", "Chargeback", FormMethod.Post))
{
@Html.AntiForgeryToken()
<div>
@Html.ActionLink("Back to List", "Index")
</div>
<div class="container">
<h4 id="details">Summary</h4>
<div class="row">
<div class="col-sm-4">
<div class="HColor">
@Html.Label("Fault")
</div>
@Html.DropDownList("FaultName", new SelectList(Model._TheFaults, "Id", "Name"), new { @class = "form-control" })
</div>
</div>
</div>
}
[HttpPost]
public ActionResult Save(Chargeback model)
{
var chargebackInDb = db.Chargebacks.Single(x=> x.Id == model.Id);
if (chargebackInDb != null && ModelState.IsValid)
{
chargebackInDb.FaultId = model.FactoryId;
db.SaveChanges();
return RedirectToAction("Index");
}
return RedirectToAction("Save");
}
我希望它返回值,但它返回null。