0

我不知道是什么原因,它是如此直接和简单,但奇怪的是,它不起作用。我总是在控制器中收到NULL模型。这是代码:

模型

public class EnrolleePlaces
{
    [HiddenInput(DisplayValue=false)]
    public int id { get; set; }

    public string SpecialtyCode { get; set; }

    public string Specialty { get; set; }

    public int Places { get; set; }
}

控制器

public ViewResult EditPlaces(int id)
{
      return View(repo.EnrolleePlaces.FirstOrDefault(p => p.id == id));
}

[HttpPost]
public ActionResult NewPlaces(EnrolleePlaces places) // 'places' is ALWAYS null
{
       if (ModelState.IsValid)
       {
           repo.SaveEnrolleePlaces(places);
           return RedirectToAction("Settings");
       }
       return View("EditPlaces", places);
}

public ViewResult CreatePlaces()
{
      return View("EditPlaces", new EnrolleePlaces());
}

和一个视图

@model Domain.Entities.EnrolleePlaces

@{
    Layout = null;
}

Edit: @Model.Specialty

@using (Ajax.BeginForm("NewPlaces", "Enrollee", new { area = "Admin" },
new AjaxOptions() { UpdateTargetId = "AdminContent" } ,
new { enctype = "multipart/form-data" }))
{
    @Html.EditorForModel()
    // here is input type="submit"
}

我的项目中有超过 15 个控制器,由相同的模式制作,但只有这个很奇怪

4

1 回答 1

0

您是否尝试过更改您的操作方法接收的参数名称?

例如:

[HttpPost]
public ActionResult NewPlaces(EnrolleePlaces dd) // any name other than "places"
{
       if (ModelState.IsValid)
       {
           repo.SaveEnrolleePlaces(places);
           return RedirectToAction("Settings");
       }
       return View("EditPlaces", places);
}
于 2013-11-14T10:55:20.337 回答