Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.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# Html.DropDownListFor&;Html.checkboxfordonds';不要反思制度_C#_Asp.net Mvc 4 - Fatal编程技术网

C# Html.DropDownListFor&;Html.checkboxfordonds';不要反思制度

C# Html.DropDownListFor&;Html.checkboxfordonds';不要反思制度,c#,asp.net-mvc-4,C#,Asp.net Mvc 4,我有一个模型,看起来像: public class schoolModel { public SelectList Categories; public school Entity; } public class school { int? CategoryId{get;set;} // foreingKey bool IncludeAttached{get;set;} } 学校看起来像: public class schoolModel { public

我有一个模型,看起来像:

public class schoolModel
{
    public SelectList Categories;
    public school Entity;


}
public class school 
{

int? CategoryId{get;set;} // foreingKey
bool IncludeAttached{get;set;}

}
学校看起来像:

public class schoolModel
{
    public SelectList Categories;
    public school Entity;


}
public class school 
{

int? CategoryId{get;set;} // foreingKey
bool IncludeAttached{get;set;}

}
我初始化学校模型如下:

var model = new schoolModel();
            model.Entity = schoolServiceAgent.Output.Entities.FirstOrDefault(n => n.Id == id);
            model.Categories = new SelectList(new GenderServiceAgent().GetCategoriesByAlias(null, true), "Id", "Alias", model.Entity.CategoryId);
我用它们就像

@Html.DropDownListFor(model => model.Entity.CategoryId, new SelectList(Model.Categories, "Value", "Text"), Model.Entity.CategoryId)
@Html.CheckBoxFor(model => model.Entity.IncludeAttached.Value, new { @class = "form-control placeholder-no-fix", name = "IncludeAttached", @checked = "checked" })
但是在编辑文章中,FormCollection对于CategoryId没有任何值,并且IncludeAttached

我试着让他们使用

public ActionResult Edit(int id, FormCollection collection)
{
    var categoryid = int.Parse(collection["CategoryId"]); 
    var result = selectedschool.inMediaArabicApp = bool.Parse(collection["IncludeAttached"]);

}   
上面提到的引发空异常,你知道如何解决吗?围绕编辑的表单如下所示

@using (@Html.BeginForm("Edit", "Schools", FormMethod.Post,
                             new { enctype = "multipart/form-data" }))
{

与其使用FormCollection,不如使用.Net功能

使用
[HttpPost]
,因为您是从表单发布的

[HttpPost]
public ActionResult Edit(School model)
{
   var categoryid = model.CategoryId; 
   var result = model.IncludeAttached;

} 

此外,c#约定将用于类名和变量。

为什么不使用FormCollection呢

使用
[HttpPost]
,因为您是从表单发布的

[HttpPost]
public ActionResult Edit(School model)
{
   var categoryid = model.CategoryId; 
   var result = model.IncludeAttached;

} 

此外,c#约定将用于类名和变量。

为什么不使用FormCollection呢

使用
[HttpPost]
,因为您是从表单发布的

[HttpPost]
public ActionResult Edit(School model)
{
   var categoryid = model.CategoryId; 
   var result = model.IncludeAttached;

} 

此外,c#约定将用于类名和变量。

为什么不使用FormCollection呢

使用
[HttpPost]
,因为您是从表单发布的

[HttpPost]
public ActionResult Edit(School model)
{
   var categoryid = model.CategoryId; 
   var result = model.IncludeAttached;

} 

此外,c#约定用于类名和变量。

是否安装了Fiddler?您能告诉我您的表单正在发送回服务器吗?您是否安装了Fiddler?您能告诉我您的表单正在发送回服务器吗?您是否安装了Fiddler?您能告诉我您的表单正在发送回服务器吗?您是否安装了Fiddler?你能告诉我你的表单发送回服务器的是什么吗?你能添加你的HTML
表单
代码吗?我更新问题如果你正在使用
POST
,那么你需要在控制器操作
[HttpPost]上添加注释
能否添加HTML
表单
代码?我会更新问题如果您使用的是
POST
,则需要在控制器操作
[HttpPost]上添加注释
能否添加HTML
表单
代码?我会更新问题如果您使用的是
POST
,则需要在控制器操作
[HttpPost]上添加注释
能否添加HTML
表单
代码?我会更新问题如果您使用的是
POST
,则需要在控制器操作
[HttpPost]