删除不显示所选记录的页面

时间:2013-12-13 20:45:00

标签: linq webforms repository asp.net-mvc-routing

这是家庭作业,ASP.NET MVC和Web表单Web应用程序使用存储库(数据硬编码,没有数据库)来评估医生。用户应该能够编辑和删除记录,但是当运行应用程序并且其中一个记录按下“删除”链接时,“删除”页面不会显示该记录的详细信息。为什么不?

enter image description here

以下是删除方法:

public ActionResult Delete(string DoctorPicture)
        {
            repo.Remove(DoctorPicture);
            return View("Delete");
        }


[HttpPost]
    public ActionResult Delete(string DoctorPicture, FormCollection collection)
    {
        try
        {
            // TODO: Add delete logic here
            repo.Remove(DoctorPicture);
            return View("Delete");
        }
        catch
        {
            return View();
        }
    }

repo.Remove(DoctorPicture);来到TestDoctorRepository,医生为空。它应该是吗?

public void Remove(string DoctorPicture)
        {
            var doctor = from d in doctors where d.DoctorPicture == DoctorPicture select d;
            doctors.Remove(doctor.FirstOrDefault());
        }

这就是我的医生名单。我的图片路径是否有问题?

public TestDoctorRepository()
        {
            doctors = new List<Doctor> {
                new Doctor { DoctorPicture = "Images/0cropped.jpg", DoctorName = "Michael Shores", DoctorSpecialty = "Opthamology", times = 0, rating = 0, rated = true, avg=0, fave = true },
            //more doctors
            };
        }

public Doctor GetDoctorByDoctorPicture(string DoctorPicture)
        {
            var selectedDoctor = from d in doctors
                                 where d.DoctorPicture == DoctorPicture
                                 select d;
            return selectedDoctor.FirstOrDefault();
        }

删除视图:

@model MidtermApplication.Models.Doctor

@{
    ViewBag.Title = "Delete";
}

<h2>Delete</h2>

<h3>Are you sure you want to delete this?</h3>
<fieldset>
    <legend>Doctor</legend>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.DoctorPicture)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.DoctorPicture)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.DoctorName)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.DoctorName)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.DoctorSpecialty)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.DoctorSpecialty)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.rating)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.rating)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.times)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.times)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.fave)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.fave)
    </div>

    <div class="display-label">
         @Html.DisplayNameFor(model => model.rated)
    </div>
    <div class="display-field">
        @Html.DisplayFor(model => model.rated)
    </div>
</fieldset>
@using (Html.BeginForm()) {
    <p>
        <input type="submit" value="Delete" /> |
        @Html.ActionLink("Back to List", "Index")
    </p>
}

0 个答案:

没有答案