表单数据未返回数据

时间:2019-06-24 14:12:42

标签: c# asp.net-mvc forms

我无法弄清楚为什么我无法检索表单数据。在下面提供的工作中,添加了视图,viewmodel和控制器。请让我知道是否需要其他信息:

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。

0 个答案:

没有答案