Asp.net mvc 对象引用未设置为Asp.net MVC(编辑页)中对象的实例

Asp.net mvc 对象引用未设置为Asp.net MVC(编辑页)中对象的实例,asp.net-mvc,model-view-controller,Asp.net Mvc,Model View Controller,我只想对图像和其他学生信息进行CRUD操作。当我打开编辑页面时,我就知道了 编辑视图的代码: <div class="container-fluid"> <div class="row"> <div class="jumbotron jumbotron-fluid"> <div class="container"> <h1 class="display-4">ÖĞRENCİ DÜZENL

我只想对图像和其他学生信息进行CRUD操作。当我打开编辑页面时,我就知道了

编辑视图的代码:

<div class="container-fluid">
<div class="row">

    <div class="jumbotron jumbotron-fluid">
        <div class="container">
            <h1 class="display-4">ÖĞRENCİ DÜZENLEME SAYFASI</h1>
            <p class="lead">Bu ekrandan öğrenci bilgilerini düzenleyebilirsiniz.</p>
        </div>
    </div>

    <div class="btn btn-light">
        @Html.ActionLink("  Öğrenci Listesine Geri Dön", "Index", null, new { @class = "btn btn-warning fa fa-list" })
    </div>

    @using (Html.BeginForm("Edit", "Student", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.Id)
        <hr />
        <div class="col-md-5">
            <div class="form-group">
                <label>ALAN</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-graduation-cap"></i></span>
                    @Html.EditorFor(model => model.Type, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Alanını Giriniz. Örneğin; Sayısal, Sözel</small>
                @Html.ValidationMessageFor(model => model.Type, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>SINIF</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-users"></i></span>
                    @Html.DropDownList("Class_Id", null, htmlAttributes: new { @class = "form-control" })
                </div>
                <small class="form-text text-muted">Öğrenci Sınıfını Seçiniz</small>
                @Html.ValidationMessageFor(model => model.Class_Id, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>GRUP</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-indent"></i></span>
                    @Html.DropDownList("Group_Id", null, htmlAttributes: new { @class = "form-control" })
                </div>
                <small class="form-text text-muted">Öğrenci hazırlandığı sınav türünü seçiniz</small>
                @Html.ValidationMessageFor(model => model.Group_Id, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>TC NUMARASI</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-id-card-o"></i></span>
                    @Html.EditorFor(model => model.TCno, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci TC Kimlik numarası giriniz</small>
                @Html.ValidationMessageFor(model => model.TCno, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>AD</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-font"></i></span>
                    @Html.EditorFor(model => model.FName, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Ad</small>
                @Html.ValidationMessageFor(model => model.FName, "", new { @class = "text-danger" })
            </div>



            <div class="form-group">
                <label>SOYAD</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-strikethrough"></i></span>
                    @Html.EditorFor(model => model.LName, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Soyadı Giriniz</small>
                @Html.ValidationMessageFor(model => model.LName, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>CİNSİYET</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-intersex"></i></span>
                    <table>
                        <tr>
                            <td>@Html.RadioButtonFor(model => model.Gender, true) <strong>Bay</strong></td>
                            <td> &nbsp; &nbsp;&nbsp; </td>
                            <td>@Html.RadioButtonFor(model => model.Gender, false) <strong>Bayan</strong></td>
                        </tr>
                    </table>
                </div>
                <small class="form-text text-muted">Öğrenci Cinsiyeti seçiniz</small>
                @Html.ValidationMessageFor(model => model.Gender, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>DOĞUM TARİHİ</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    @Html.EditorFor(model => model.Birthday, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Doğum Tarihi</small>
                @Html.ValidationMessageFor(model => model.Birthday, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>ÖĞRENCİ TELEFON</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-phone"></i></span>
                    @Html.EditorFor(model => model.Phone, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Mobil telefon numarası giriniz. Ör: 05xx xxx xxxx</small>
                @Html.ValidationMessageFor(model => model.Phone, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>DURUM</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-toggle-on"></i></span>
                    <table>
                        <tr>
                            <td>@Html.RadioButtonFor(model => model.Status, true) <strong>Aktif</strong></td>
                            <td> &nbsp; &nbsp;&nbsp; </td>
                            <td>@Html.RadioButtonFor(model => model.Status, false) <strong>Pasif</strong></td>
                        </tr>
                    </table>
                </div>
                <small class="form-text text-muted">Öğrenci Durumunu seçiniz</small>
                @Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>FOTOĞRAF</label>
                <div class="input-group">
                    <img src="@Url.Content(Session["Image"].ToString())" height="100" width="100" />
                    <br />
                    <input type="file" class="custom-file-input" value="Dosya Seç..." name="ImageFile">
                </div>
                <small class="form-text text-muted">Öğrenci fotoğrafı seçiniz. 1 MB küçük |.png|.jpg|.jpeg uzantılı dosyayı seçiniz.</small>
                @Html.ValidationMessageFor(model => model.Photo, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="col-md-1"></div>

        <div class="col-md-5">
            <div class="form-group">
                <label>E-POSTA</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-envelope"></i></span>
                    @Html.EditorFor(model => model.eMail, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Sisteme giriş yapabilmesi için bir E-Posta adresi giriniz.</small>
                @Html.ValidationMessageFor(model => model.eMail, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>ŞİFRE</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-key"></i></span>
                    @Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Sisteme giriş yapabilmesi için bir şifre giriniz.</small>
                @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
            </div>


            <div class="form-group">
                <label>KATILMA TARİHİ</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-check-circle-o"></i></span>
                    @Html.EditorFor(model => model.DateOfJoin, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Katılma tarihini giriniz.</small>
                @Html.ValidationMessageFor(model => model.DateOfJoin, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>AYRILMA TARİHİ</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-circle-o"></i></span>
                    @Html.EditorFor(model => model.DateOfLeave, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Ayrılma tarihini seçiniz.</small>
            </div>

            <div class="form-group">
                <label>ADRES</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-map-marker"></i></span>
                    @Html.TextAreaFor(model => model.Address, new { @class = "form-control", @style = "height: 100px" })
                </div>
                <small class="form-text text-muted">Öğrenci Adres'ini giriniz.</small>
                @Html.ValidationMessageFor(model => model.Address, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>VELİ AD</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-id-badge"></i></span>
                    @Html.EditorFor(model => model.ParentName, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci'nin Veli adını giriniz.</small>
                @Html.ValidationMessageFor(model => model.ParentName, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>VELİ TELEFON 1</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-mobile"></i></span>
                    @Html.EditorFor(model => model.ParentPhone1, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci'nin Veli Telefon numarasını giriniz.</small>
                @Html.ValidationMessageFor(model => model.ParentPhone1, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>VELİ TELEFON 2</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-phone"></i></span>
                    @Html.EditorFor(model => model.ParentPhone2, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci'nin Veli yedek telefon numarasını giriniz.</small>
            </div>

            <div class="form-group">
                <label>VELİ CİNSİYET</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-intersex"></i></span>
                    <table>
                        <tr>
                            <td>@Html.RadioButtonFor(model => model.ParentGender, true) <strong>Bay</strong></td>
                            <td> &nbsp; &nbsp;&nbsp; </td>
                            <td>@Html.RadioButtonFor(model => model.ParentGender, false) <strong>Bayan</strong></td>
                        </tr>
                    </table>
                </div>
                <small class="form-text text-muted">Veli'nin cinsiyetini seçiniz.</small>
                @Html.ValidationMessageFor(model => model.ParentGender, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>AÇIKLAMA</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-align-justify"></i></span>
                    @Html.TextAreaFor(model => model.Description, new { @class = "form-control", @style = "height: 100px" })
                </div>
                <small class="form-text text-muted">Öğrenci için bir açıklama giriniz.</small>
                @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="col-md-1"></div>
        <br />
        <br />
        <div class="form-group">
            <div class="col-md-12">
                <button type="submit" class="btn btn-success ">
                    <i class="fa fa-floppy-o">&nbsp; &nbsp;Değişiklikleri Kaydet</i>
                </button>
            </div>
        </div>
        <br />
        <br />
    }
</div>
private DBClassroomEntities db = new DBClassroomEntities();
/ GET: Student/Edit/5
    public ActionResult Edit(int? id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        var student = db.Students.Find(id);
        if (student == null)
        {
            return HttpNotFound();
        }
        ViewBag.Class_Id = new SelectList(db.Classes, "ID", "Name", student.Class_Id);
        ViewBag.Group_Id = new SelectList(db.Groups, "ID", "Name", student.Group_Id);
        return View(student);
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Edit(Student student)
    { //does not enter here because I can't see the old data in Student.
        if (ModelState.IsValid)
        {
            db.Entry(student).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        ViewBag.Class_Id = new SelectList(db.Classes, "ID", "Name", student.Class_Id);
        ViewBag.Group_Id = new SelectList(db.Groups, "ID", "Name", student.Group_Id);
        return View(student);
    }
学生模型代码

public partial class Student
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public Student()
    {
        this.Discontinuities = new HashSet<Discontinuity>();
        this.Grades = new HashSet<Grade>();
        this.Payments = new HashSet<Payment>();
    }

    public int Id { get; set; }
    public string Type { get; set; }
    public Nullable<int> Class_Id { get; set; }
    public Nullable<int> Group_Id { get; set; }
    public string TCno { get; set; }
    public string FName { get; set; }
    public string LName { get; set; }
    public bool Gender { get; set; }
    public Nullable<System.DateTime> Birthday { get; set; }
    public string Phone { get; set; }
    public string eMail { get; set; }
    public string Password { get; set; }
    public bool Status { get; set; }
    public Nullable<System.DateTime> DateOfJoin { get; set; }
    public Nullable<System.DateTime> DateOfLeave { get; set; }
    public string Address { get; set; }
    public string ParentName { get; set; }
    public string ParentPhone1 { get; set; }
    public string ParentPhone2 { get; set; }
    public bool ParentGender { get; set; }
    public string Photo { get; set; }
    public string Description { get; set; }

    //public HttpPostedFileBase filex { get; set; }

    public virtual Class Class { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Discontinuity> Discontinuities { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Grade> Grades { get; set; }
    public virtual Group Group { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Payment> Payments { get; set; }
}
公立部分班学生
{
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2214:DoNotCallOverridableMethodsInConstructors”)]
公立学生()
{
this.intercontinuations=newhashset();
this.Grades=新的HashSet();
this.Payments=newhashset();
}
公共int Id{get;set;}
公共字符串类型{get;set;}
公共可空类_Id{get;set;}
公共可空组_Id{get;set;}
公共字符串TCno{get;set;}
公共字符串FName{get;set;}
公共字符串LName{get;set;}
公共布尔性别{get;set;}
公共可空生日{get;set;}
公用字符串电话{get;set;}
公共字符串电子邮件{get;set;}
公共字符串密码{get;set;}
公共布尔状态{get;set;}
公共可为空的DateOfJoin{get;set;}
公共可为空的DateOfLeave{get;set;}
公共字符串地址{get;set;}
公共字符串ParentName{get;set;}
公共字符串ParentPhone1{get;set;}
公共字符串ParentPhone2{get;set;}
公共bool ParentGender{get;set;}
公共字符串Photo{get;set;}
公共字符串说明{get;set;}
//公共HttpPostedFileBase文件{get;set;}
公共虚拟类{get;set;}
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2227:CollectionPropertiesShouldBreadOnly”)]
公共虚拟ICollection中断{get;set;}
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2227:CollectionPropertiesShouldBreadOnly”)]
公共虚拟ICollection级别{get;set;}
公共虚拟组{get;set;}
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2227:CollectionPropertiesShouldBreadOnly”)]
公共虚拟ICollection付款{get;set;}
}
和错误:

<div class="container-fluid">
<div class="row">

    <div class="jumbotron jumbotron-fluid">
        <div class="container">
            <h1 class="display-4">ÖĞRENCİ DÜZENLEME SAYFASI</h1>
            <p class="lead">Bu ekrandan öğrenci bilgilerini düzenleyebilirsiniz.</p>
        </div>
    </div>

    <div class="btn btn-light">
        @Html.ActionLink("  Öğrenci Listesine Geri Dön", "Index", null, new { @class = "btn btn-warning fa fa-list" })
    </div>

    @using (Html.BeginForm("Edit", "Student", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        @Html.AntiForgeryToken()
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.Id)
        <hr />
        <div class="col-md-5">
            <div class="form-group">
                <label>ALAN</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-graduation-cap"></i></span>
                    @Html.EditorFor(model => model.Type, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Alanını Giriniz. Örneğin; Sayısal, Sözel</small>
                @Html.ValidationMessageFor(model => model.Type, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>SINIF</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-users"></i></span>
                    @Html.DropDownList("Class_Id", null, htmlAttributes: new { @class = "form-control" })
                </div>
                <small class="form-text text-muted">Öğrenci Sınıfını Seçiniz</small>
                @Html.ValidationMessageFor(model => model.Class_Id, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>GRUP</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-indent"></i></span>
                    @Html.DropDownList("Group_Id", null, htmlAttributes: new { @class = "form-control" })
                </div>
                <small class="form-text text-muted">Öğrenci hazırlandığı sınav türünü seçiniz</small>
                @Html.ValidationMessageFor(model => model.Group_Id, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>TC NUMARASI</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-id-card-o"></i></span>
                    @Html.EditorFor(model => model.TCno, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci TC Kimlik numarası giriniz</small>
                @Html.ValidationMessageFor(model => model.TCno, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>AD</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-font"></i></span>
                    @Html.EditorFor(model => model.FName, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Ad</small>
                @Html.ValidationMessageFor(model => model.FName, "", new { @class = "text-danger" })
            </div>



            <div class="form-group">
                <label>SOYAD</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-strikethrough"></i></span>
                    @Html.EditorFor(model => model.LName, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Soyadı Giriniz</small>
                @Html.ValidationMessageFor(model => model.LName, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>CİNSİYET</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-intersex"></i></span>
                    <table>
                        <tr>
                            <td>@Html.RadioButtonFor(model => model.Gender, true) <strong>Bay</strong></td>
                            <td> &nbsp; &nbsp;&nbsp; </td>
                            <td>@Html.RadioButtonFor(model => model.Gender, false) <strong>Bayan</strong></td>
                        </tr>
                    </table>
                </div>
                <small class="form-text text-muted">Öğrenci Cinsiyeti seçiniz</small>
                @Html.ValidationMessageFor(model => model.Gender, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>DOĞUM TARİHİ</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    @Html.EditorFor(model => model.Birthday, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Doğum Tarihi</small>
                @Html.ValidationMessageFor(model => model.Birthday, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>ÖĞRENCİ TELEFON</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-phone"></i></span>
                    @Html.EditorFor(model => model.Phone, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Mobil telefon numarası giriniz. Ör: 05xx xxx xxxx</small>
                @Html.ValidationMessageFor(model => model.Phone, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>DURUM</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-toggle-on"></i></span>
                    <table>
                        <tr>
                            <td>@Html.RadioButtonFor(model => model.Status, true) <strong>Aktif</strong></td>
                            <td> &nbsp; &nbsp;&nbsp; </td>
                            <td>@Html.RadioButtonFor(model => model.Status, false) <strong>Pasif</strong></td>
                        </tr>
                    </table>
                </div>
                <small class="form-text text-muted">Öğrenci Durumunu seçiniz</small>
                @Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>FOTOĞRAF</label>
                <div class="input-group">
                    <img src="@Url.Content(Session["Image"].ToString())" height="100" width="100" />
                    <br />
                    <input type="file" class="custom-file-input" value="Dosya Seç..." name="ImageFile">
                </div>
                <small class="form-text text-muted">Öğrenci fotoğrafı seçiniz. 1 MB küçük |.png|.jpg|.jpeg uzantılı dosyayı seçiniz.</small>
                @Html.ValidationMessageFor(model => model.Photo, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="col-md-1"></div>

        <div class="col-md-5">
            <div class="form-group">
                <label>E-POSTA</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-envelope"></i></span>
                    @Html.EditorFor(model => model.eMail, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Sisteme giriş yapabilmesi için bir E-Posta adresi giriniz.</small>
                @Html.ValidationMessageFor(model => model.eMail, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>ŞİFRE</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-key"></i></span>
                    @Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Sisteme giriş yapabilmesi için bir şifre giriniz.</small>
                @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
            </div>


            <div class="form-group">
                <label>KATILMA TARİHİ</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-check-circle-o"></i></span>
                    @Html.EditorFor(model => model.DateOfJoin, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Katılma tarihini giriniz.</small>
                @Html.ValidationMessageFor(model => model.DateOfJoin, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>AYRILMA TARİHİ</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-circle-o"></i></span>
                    @Html.EditorFor(model => model.DateOfLeave, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci Ayrılma tarihini seçiniz.</small>
            </div>

            <div class="form-group">
                <label>ADRES</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-map-marker"></i></span>
                    @Html.TextAreaFor(model => model.Address, new { @class = "form-control", @style = "height: 100px" })
                </div>
                <small class="form-text text-muted">Öğrenci Adres'ini giriniz.</small>
                @Html.ValidationMessageFor(model => model.Address, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>VELİ AD</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-id-badge"></i></span>
                    @Html.EditorFor(model => model.ParentName, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci'nin Veli adını giriniz.</small>
                @Html.ValidationMessageFor(model => model.ParentName, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>VELİ TELEFON 1</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-mobile"></i></span>
                    @Html.EditorFor(model => model.ParentPhone1, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci'nin Veli Telefon numarasını giriniz.</small>
                @Html.ValidationMessageFor(model => model.ParentPhone1, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>VELİ TELEFON 2</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-phone"></i></span>
                    @Html.EditorFor(model => model.ParentPhone2, new { htmlAttributes = new { @class = "form-control" } })
                </div>
                <small class="form-text text-muted">Öğrenci'nin Veli yedek telefon numarasını giriniz.</small>
            </div>

            <div class="form-group">
                <label>VELİ CİNSİYET</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-intersex"></i></span>
                    <table>
                        <tr>
                            <td>@Html.RadioButtonFor(model => model.ParentGender, true) <strong>Bay</strong></td>
                            <td> &nbsp; &nbsp;&nbsp; </td>
                            <td>@Html.RadioButtonFor(model => model.ParentGender, false) <strong>Bayan</strong></td>
                        </tr>
                    </table>
                </div>
                <small class="form-text text-muted">Veli'nin cinsiyetini seçiniz.</small>
                @Html.ValidationMessageFor(model => model.ParentGender, "", new { @class = "text-danger" })
            </div>

            <div class="form-group">
                <label>AÇIKLAMA</label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-align-justify"></i></span>
                    @Html.TextAreaFor(model => model.Description, new { @class = "form-control", @style = "height: 100px" })
                </div>
                <small class="form-text text-muted">Öğrenci için bir açıklama giriniz.</small>
                @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="col-md-1"></div>
        <br />
        <br />
        <div class="form-group">
            <div class="col-md-12">
                <button type="submit" class="btn btn-success ">
                    <i class="fa fa-floppy-o">&nbsp; &nbsp;Değişiklikleri Kaydet</i>
                </button>
            </div>
        </div>
        <br />
        <br />
    }
</div>
private DBClassroomEntities db = new DBClassroomEntities();
/ GET: Student/Edit/5
    public ActionResult Edit(int? id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        var student = db.Students.Find(id);
        if (student == null)
        {
            return HttpNotFound();
        }
        ViewBag.Class_Id = new SelectList(db.Classes, "ID", "Name", student.Class_Id);
        ViewBag.Group_Id = new SelectList(db.Groups, "ID", "Name", student.Group_Id);
        return View(student);
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Edit(Student student)
    { //does not enter here because I can't see the old data in Student.
        if (ModelState.IsValid)
        {
            db.Entry(student).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        ViewBag.Class_Id = new SelectList(db.Classes, "ID", "Name", student.Class_Id);
        ViewBag.Group_Id = new SelectList(db.Groups, "ID", "Name", student.Group_Id);
        return View(student);
    }

因此,我将处理这个错误一周。抱歉,代码太长了

注意:如果我删除了第180行中的div,则在其他地方会出现错误

谢谢你的帮助

更新: 默认情况下,它是工作视图

<h2>Edit</h2>

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
    <h4>Student</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    @Html.HiddenFor(model => model.Id)

    <div class="form-group">
        @Html.LabelFor(model => model.Type, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Type, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Type, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Class_Id, "Class_Id", htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.DropDownList("Class_Id", null, htmlAttributes: new { @class = "form-control" })
            @Html.ValidationMessageFor(model => model.Class_Id, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Group_Id, "Group_Id", htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.DropDownList("Group_Id", null, htmlAttributes: new { @class = "form-control" })
            @Html.ValidationMessageFor(model => model.Group_Id, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.TCno, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.TCno, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.TCno, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.FName, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.FName, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.FName, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.LName, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.LName, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.LName, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Gender, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            <div class="checkbox">
                @Html.EditorFor(model => model.Gender)
                @Html.ValidationMessageFor(model => model.Gender, "", new { @class = "text-danger" })
            </div>
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Birthday, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Birthday, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Birthday, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Phone, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Phone, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Phone, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.eMail, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.eMail, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.eMail, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Status, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            <div class="checkbox">
                @Html.EditorFor(model => model.Status)
                @Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
            </div>
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.DateOfJoin, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.DateOfJoin, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.DateOfJoin, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.DateOfLeave, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.DateOfLeave, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.DateOfLeave, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Address, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Address, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Address, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.ParentName, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.ParentName, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.ParentName, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.ParentPhone1, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.ParentPhone1, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.ParentPhone1, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.ParentPhone2, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.ParentPhone2, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.ParentPhone2, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.ParentGender, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            <div class="checkbox">
                @Html.EditorFor(model => model.ParentGender)
                @Html.ValidationMessageFor(model => model.ParentGender, "", new { @class = "text-danger" })
            </div>
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Photo, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Photo, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Photo, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
        </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>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>
编辑
@使用(Html.BeginForm())
{
@Html.AntiForgeryToken()
学生

@Html.ValidationSummary(true,“,new{@class=“text danger”}) @Html.HiddenFor(model=>model.Id) @LabelFor(model=>model.Type,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.Type,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.Type,“,new{@class=“text danger”}) @LabelFor(model=>model.Class_Id,“Class_Id”,htmlAttributes:new{@Class=“controllabel col-md-2”}) @DropDownList(“Class_Id”,null,htmlAttributes:new{@Class=“form control”}) @Html.ValidationMessageFor(model=>model.Class_Id,“,new{@Class=“text danger”}) @LabelFor(model=>model.Group_Id,“Group_Id”,htmlAttributes:new{@class=“controllabel col-md-2”}) @DropDownList(“Group_Id”,null,htmlAttributes:new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.Group_Id,“,new{@class=“text danger”}) @LabelFor(model=>model.TCno,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.TCno,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.TCno,“,new{@class=“text danger”}) @LabelFor(model=>model.FName,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.FName,new{htmlAttributes=new{@class=“form control”}}) @Html.ValidationMessageFor(model=>model.FName,“,new{@class=“text danger”}) @LabelFor(model=>model.LName,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.LName,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.LName,“,new{@class=“text danger”}) @LabelFor(model=>model.Gender,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.Gender) @Html.ValidationMessageFor(model=>model.Gender,“,new{@class=“text danger”}) @LabelFor(model=>model.birth,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.Birthday,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.birth,“,new{@class=“text danger”}) @LabelFor(model=>model.Phone,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.Phone,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.Phone,“,new{@class=“text danger”}) @LabelFor(model=>model.eMail,htmlAttributes:new{@class=“controllabel col-md-2”}) @EditorFor(model=>model.eMail,new{htmlAttributes=new{@class=“form control”}) @Html.ValidationMessageFor(model=>model.eMail,
<img src="@Url.Content(Session["Image"].ToString())" height="100" width="100" />
Session["Image"] it's null