编辑时c#值不会改变

时间:2017-04-23 03:39:21

标签: c# asp.net-mvc-4

我正在使用asp.net MVC4,每当我尝试更改编辑页面中的值时,我都会得到error message

这是我的控制器

   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>

我尝试更改按钮进行输入并尝试使用onlick,我不确定问题是使用方法还是使用html,如果有更多信息,我还不熟悉编码需要发布请告诉我。

0 个答案:

没有答案