编辑时c#值不改变
我使用的是asp.net MVC4,每当我试图更改编辑页面中的值时,我都会得到以下结果 这是我的控制器`编辑时c#值不改变,c#,asp.net-mvc-4,C#,Asp.net Mvc 4,我使用的是asp.net MVC4,每当我试图更改编辑页面中的值时,我都会得到以下结果 这是我的控制器` public ActionResult Edit( Maison maison) { if (ModelState.IsValid) { ms.Update(maison); ms.Commit(); return RedirectToAction("Index");
public ActionResult Edit( Maison maison)
{
if (ModelState.IsValid)
{
ms.Update(maison);
ms.Commit();
return RedirectToAction("Index");
}
return View(maison);
}
这是我的HTML
<div class="center">
<div class="container">
<div class="row">
<div class="site site--main">
<header class="site__header">
<h1 class="site__title">Modifier votre annonce</h1>
</header>
<div class="site__panel"><span class="site__header-text">Veuillez remplir les champs avec les informations nécessaires, tout les champs avec * sont obligatoire.</span></div>
<div class="site__main">
<form method="post" action="@Url.Action("Edit","Maisons" , FormMethod.Post)" class="form form--flex form--property-add js-form js-form-property">
@Html.AntiForgeryToken()
<div class="widget js-widget widget--main widget--no-margin widget--no-border widget--collapse">
<div class="widget__header">
<h2 class="widget__title">Informations de base</h2>
</div>
<div class="widget__content">
<div class="row">
<div class="form-group">
@Html.LabelFor(model => model.Titre, htmlAttributes: new { @class = "control-label" })
@Html.EditorFor(model => model.Titre, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Titre, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.Tutile, htmlAttributes: new { @class = "control-label ", @type = "required" })
@Html.EnumDropDownListFor(model => model.Tutile, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Tutile, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.type, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EnumDropDownListFor(model => model.type, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.type, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.Dimension, htmlAttributes: new { @class = "control-label " })
@Html.EditorFor(model => model.Dimension, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Dimension, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.Ville, htmlAttributes: new { @class = "control-label " })
@Html.EnumDropDownListFor(model => model.Ville, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Ville, "", new { @class = "text-danger" })
</div>
<!-- end of block .form-property__control-->
<div class="form-group">
@Html.LabelFor(model => model.prix, htmlAttributes: new { @class = "control-label " })
@Html.EditorFor(model => model.prix, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.prix, "", new { @class = "text-danger" })
</div>
</div>
</div>
</div>
<div class="widget js-widget widget--main widget--no-margin widget--no-border widget--collapse">
<div class="widget__header">
<h2 class="widget__title">Plus d'Information</h2>
</div>
<div class="widget__content">
<div class="row">
<div class="form-group">
@Html.LabelFor(model => model.nbrchambre, htmlAttributes: new { @class = "control-label col-md-2" })
@Html.EditorFor(model => model.nbrchambre, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.nbrchambre, "", new { @class = "text-danger" })
<!-- end of block .form-property__control-->
</div>
<div class="form-group">
@Html.LabelFor(model => model.NbrBathRooms, htmlAttributes: new { @class = "control-label " })
@Html.EditorFor(model => model.NbrBathRooms, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NbrBathRooms, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(model => model.NbrGarages, htmlAttributes: new { @class = "control-label " })
@Html.EditorFor(model => model.NbrGarages, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NbrGarages, "", new { @class = "text-danger" })
</div>
<div class="form-group form-group--col-12">
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label " })
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
</div>
</div>
</div>
</div>
<div class="row">
<button class="form__submit">Modifier</button>
</div>
</form>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
修饰符votre ANNOCE
维列兹·雷姆普利尔是一家信息服务公司,他是一家义务服务公司。
@Html.AntiForgeryToken()
数据库信息
@LabelFor(model=>model.Titre,htmlAttributes:new{@class=“control label”})
@EditorFor(model=>model.Titre,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.Titre,“,new{@class=“text danger”})
@LabelFor(model=>model.Tutile,htmlAttributes:new{@class=“control label”,@type=“required”})
@EnumDropDownListFor(model=>model.Tutile,htmlAttributes:new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.Tutile,“,new{@class=“text danger”})
@LabelFor(model=>model.type,htmlAttributes:new{@class=“controllabel col-md-2”})
@EnumDropDownListFor(model=>model.type,htmlAttributes:new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.type,“,new{@class=“text danger”})
@LabelFor(model=>model.Dimension,htmlAttributes:new{@class=“control label”})
@EditorFor(model=>model.Dimension,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.Dimension,“,new{@class=“text danger”})
@LabelFor(model=>model.Ville,htmlAttributes:new{@class=“control label”})
@EnumDropDownListFor(model=>model.Ville,htmlAttributes:new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.Ville,“,new{@class=“text danger”})
@LabelFor(model=>model.prix,htmlAttributes:new{@class=“control label”})
@EditorFor(model=>model.prix,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.prix,“,new{@class=“text danger”})
加上d'Information
@LabelFor(model=>model.nbrchambre,htmlAttributes:new{@class=“controllabel col-md-2”})
@EditorFor(model=>model.nbrchambre,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.nbrchambre,“,new{@class=“text danger”})
@LabelFor(model=>model.nbr浴室,htmlAttributes:new{@class=“control label”})
@EditorFor(model=>model.NbrBathRooms,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.NbrBathRooms,“,new{@class=“text danger”})
@LabelFor(model=>model.nbrgarage,htmlAttributes:new{@class=“control label”})
@EditorFor(model=>model.NbrGarages,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.NbrGarages,“,new{@class=“text danger”})
@LabelFor(model=>model.Description,htmlAttributes:new{@class=“control label”})
@EditorFor(model=>model.Description,new{htmlAttributes=new{@class=“form control”})
@Html.ValidationMessageFor(model=>model.Description,“,new{@class=“text danger”})
修饰语
我尝试将按钮更改为输入,并尝试使用onlick,我不确定问题是该方法还是html,我对编码有点陌生如果有更多信息需要发布,请告诉我。图片中的错误消息清楚地表明这不是问题所在