Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 简单表单post总是向控制器发送null_C#_Asp.net_Asp.net Mvc 3_Razor - Fatal编程技术网

C# 简单表单post总是向控制器发送null

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) // '

我不知道原因是什么,它是如此直接和简单,但奇怪的是,它不起作用。I始终在控制器中接收
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
fieldTry
public 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);
}