这是我对 editcar 的看法:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<J2V.Models.vehicule>" %>
//code
<% using (Html.BeginForm("editcar", "Agence", FormMethod.Post, new { @class = "search_form" })) { %>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>vehicule</legend>
// Those colonne will not be modified
<%: Html.HiddenFor(model => model.Matv) %>
<%: Html.HiddenFor(model => model.Idag) %>
<%: Html.HiddenFor(model => model.Idcat) %>
<%: Html.HiddenFor(model => model.idmarque) %>
<%: Html.HiddenFor(model => model.modele) %>
//Colonne to edit code
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
<% } %>
这是我的控制器动作:
[HttpPost]
public ActionResult editcar(Models.vehicule model)
{
if (ModelState.IsValid)
{
entity.vehicule.AddObject(model);
entity.ObjectStateManager.ChangeObjectState(model, System.Data.EntityState.Modified);
entity.SaveChanges();
return View("index", new { id = model.Idag });
}
else
return View();
}
当我单击Update
按钮时,我收到此错误:
System.InvalidOperationException:传入字典的模型项的类型为“<> f__AnonymousType2
1 [System.String]' but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable
1 [J2V.Models.vehicule]”。