並不反映我有一個模型,看起來像:Html.DropDownListFor&Html.CheckBoxFor對系統
public class schoolModel
{
public SelectList Categories;
public school Entity;
}
哪裏上學的樣子:
public class school
{
int? CategoryId{get;set;} // foreingKey
bool IncludeAttached{get;set;}
}
我初始化schoolModel如下:
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" }))
{
你可以添加你的HTML'form'代碼嗎? –
我更新了問題 – AMH
如果您使用'POST',那麼您需要在控制器操作[HttpPost]上添加一個註釋' –