C# 简单表单post总是向控制器发送null
我不知道原因是什么,它是如此直接和简单,但奇怪的是,它不起作用。I始终在控制器中接收C# 简单表单post总是向控制器发送null,c#,asp.net,asp.net-mvc-3,razor,C#,Asp.net,Asp.net Mvc 3,Razor,我不知道原因是什么,它是如此直接和简单,但奇怪的是,它不起作用。I始终在控制器中接收NULL作为模型。 代码如下: 模型 控制器 public ViewResult EditPlaces(int id) { return View(repo.EnrolleePlaces.FirstOrDefault(p => p.id == id)); } [HttpPost] public ActionResult NewPlaces(EnrolleePlaces places) // '
NULL
作为模型。
代码如下:
模型
控制器
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个控制器,由相同的模式制作,但只有这一个是奇怪的您尝试过更改动作方法接收的参数的名称吗 例如:
[HttpPost]
public ActionResult NewPlaces(EnrolleePlaces dd) // any name other than "places"
{
if (ModelState.IsValid)
{
repo.SaveEnrolleePlaces(places);
return RedirectToAction("Settings");
}
return View("EditPlaces", places);
}
如果在控制器中设置断点并检查
请求.Form
集合,是否存在字段?@AndersAbel是的,它具有正确的数据尝试将其更改为公共操作结果NewPlaces(string places)
,这是否将参数传递给控制器?@tomsullivan1989它捕获我的int
fieldTrypublic ActionResult NewPlaces(EnrollePlaces区域)
[HttpPost]
public ActionResult NewPlaces(EnrolleePlaces dd) // any name other than "places"
{
if (ModelState.IsValid)
{
repo.SaveEnrolleePlaces(places);
return RedirectToAction("Settings");
}
return View("EditPlaces", places);
}