ASP.NEt MVC VB没有可编辑的字段丢失数据

时间:2017-05-18 09:24:36

标签: asp.net asp.net-mvc vb.net

我有一个很大的问题。之后我给了我的Html.Editor对于htmlAttribute"禁用" (所以我不能编辑那个字段)我丢失数据(数据填充为NULL),这是在我保存它之后在这个字段中。如果我删除它,一切正常。 没有出现错误,功能正常...... 我真的不知道为什么会这样......

非常感谢!

查看:

Using (Html.BeginForm())
@Html.AntiForgeryToken()

@<div class="form-horizontal">
    <h4>Dezernate</h4>
    <hr />
    @Html.ValidationSummary(true)
    @Html.HiddenFor(Function(model) model.ID)

    <div class="form-group">
        @Html.LabelFor(Function(model) model.Rechner, New With { .class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(Function(model) model.Rechner, New With {.htmlAttributes = New With {.disabled = "disabled"}})
            @Html.ValidationMessageFor(Function(model) model.Rechner)
        </div>
    </div>
     <div class="form-group">
         @Html.LabelFor(Function(model) model.Dezernat, htmlAttributes:=New With {.class = "control-label col-md-2"})
         <div class="col-md-10">
             @Html.EditorFor(Function(model) model.Dezernat, New With {.htmlAttributes = New With {.disabled = "disabled"}}) <-- See
             @Html.ValidationMessageFor(Function(model) model.Dezernat, "", New With {.class = "text-danger"})
         </div>
     </div>

    <div class="form-group">
        @Html.LabelFor(Function(model) model.Scan, New With { .class = "control-label col-md-2" })
        <div class="col-md-10">
            <div class="col-md-10">
                <select id="scan" name="Scan">
                    <option selected value= false></option>
                    <option value=true>Installiert</option>
                    <option value=false>Nicht Installiert</option>
                </select>
                @Html.ValidationMessageFor(Function(model) model.Scan)
            </div>
            </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Save" class="btn btn-default" />
        </div>
    </div>
</div>
End Using

控制器:

 <HttpPost()>
    <ValidateAntiForgeryToken()>
    Function Edit(<Bind(Include:="ID,Dezernat,Rechner,Scan,Photoshop")> ByVal dezernate As Dezernate) As ActionResult
        If ModelState.IsValid Then
            db.Entry(dezernate).State = EntityState.Modified
            db.SaveChanges()
            Return RedirectToAction("Index")
        End If
        Return View(dezernate)
    End Function

0 个答案:

没有答案