MVC .net控制器未从视图接收POST数据

时间:2019-03-14 12:06:44

标签: c# post model-view-controller

我正在尝试将数据从视图保存到Db 但我的控制器未从视图接收数据。

如果我在chrome的“网络”标签下检查程序包,它将发送具有正确值的POST,但是在调试中,我可以看到控制器接收的模型为空

我的控制器:

public class EventController : Controller
{
    private ApplicationDbContext _context;

    public EventController()
    {
        _context = new ApplicationDbContext();
    }


    [HttpPost]
    public ActionResult Save(Event walkEvent)
    {
        _context.Event.Add(walkEvent);
        _context.SaveChanges();
        return RedirectToAction("Index", "Home");
    }
}

我的观点:

@model Doggie.ViewModels.EventViewModel
@{
ViewBag.Title = "Index";
}
@using (@Html.BeginForm("Save", "Event"))
{
<div class="form-group">
    @Html.LabelFor(e => e.Event.DogOwnerName)
    @Html.ValidationMessageFor(e => e.Event.DogOwnerName)
    @Html.TextBoxFor(e => e.Event.DogOwnerName, new {@class = "form-control"})
</div>
<div class="form-group">
    @Html.LabelFor(e => e.Event.Location.Name)
    @Html.ValidationMessageFor(e => e.Event.Location.Name)
    @Html.DropDownListFor(e => e.Event.LocationId, new SelectList(Model.Location, "Id", "Name"), "Select Location", new {@class = "form-control"})
</div>
<div class="form-group">
    @Html.LabelFor(e => e.Event.Date)
    @Html.ValidationMessageFor(e => e.Event.Date)
    @Html.EditorFor(e => e.Event.Date, new {htmlAttributes = new {@class = "form-control", @placeholder = "dd/mm/yyyy"}})
</div>
<div class="form-group">
    @Html.LabelFor(e => e.Event.StartingTime)
    @Html.ValidationMessageFor(e => e.Event.StartingTime)
    @Html.TextBoxFor(e => e.Event.StartingTime, new { @class = "form-control", @placeholder="hh:mm" })
</div>
<div class="form-group">
    @Html.LabelFor(e => e.Event.EstimatedTimeMinutes)
    @Html.ValidationMessageFor(e => e.Event.EstimatedTimeMinutes)
    @Html.TextBoxFor(e => e.Event.EstimatedTimeMinutes, new { @class = "form-control", @placeholder="In minutes" })
</div>
<div class="form-group">
    @Html.LabelFor(e => e.Event.Comment)
    @Html.ValidationMessageFor(e => e.Event.Comment)
    @Html.TextAreaFor(e => e.Event.Comment, new { @class = "form-control"})
</div>

@Html.HiddenFor(e => e.Event.Id)
<button type="submit" class="btn btn-primary">Save</button>
}

我的EventViewModel:

public class EventViewModel
{
    public IEnumerable<Location> Location { get; set; }
    public Event Event { get; set; }
}

1 个答案:

答案 0 :(得分:2)

在您的postgresql.conf帖子方法参数中用LOG: invalid value for parameter "synchronous_standby_names": "postgres-02" DETAIL: syntax error at or near "-" FATAL: configuration file "/pgsql/postgresql.conf" contains errors postgresql-10.service: main process exited, code=exited, status=1/FAILURE Failed to start PostgreSQL 10 database server. -- Subject: Unit postgresql-10.service has failed -- Defined-By: systemd 替换Event

EventViewModel