Linq 删除未显示所选记录的页面
这是家庭作业,一个ASP.NETMVC和Web表单Web应用程序,使用存储库(数据硬编码,无数据库)对医生进行评分。用户应该能够编辑和删除记录,但是当应用程序运行时,并且按下其中一条记录的“删除”链接时,删除页面不会显示该记录的详细信息。为什么不呢 以下是删除方法:Linq 删除未显示所选记录的页面,linq,webforms,repository,asp.net-mvc-routing,Linq,Webforms,Repository,Asp.net Mvc Routing,这是家庭作业,一个ASP.NETMVC和Web表单Web应用程序,使用存储库(数据硬编码,无数据库)对医生进行评分。用户应该能够编辑和删除记录,但是当应用程序运行时,并且按下其中一条记录的“删除”链接时,删除页面不会显示该记录的详细信息。为什么不呢 以下是删除方法: public ActionResult Delete(string DoctorPicture) { repo.Remove(DoctorPicture); retu
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中出现,并且doctor为空。应该是吗
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();
}
publicttestdoctorrepository()
{
医生=新名单{
新医生{DoctorPicture=“Images/0cropped.jpg”,DoctorName=“Michael Shores”,DoctorSpecialty=“Opthamology”,times=0,rating=0,rated=true,avg=0,fave=true},
//更多的医生
};
}
公共医生GetDoctorByDoctorPicture(字符串DoctorPicture)
{
var selectedDoctor=来自医生中的d
其中d.DoctorPicture==DoctorPicture
选择d;
返回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>
}
@model-MidtermApplication.Models.Doctor
@{
ViewBag.Title=“删除”;
}
删除
是否确实要删除此项?
医生
@DisplayNameFor(model=>model.DoctorPicture)
@DisplayFor(model=>model.DoctorPicture)
@DisplayNameFor(model=>model.DoctorName)
@DisplayFor(model=>model.DoctorName)
@DisplayNameFor(model=>model.DoctorSpecialty)
@DisplayFor(model=>model.DoctorSpecialty)
@DisplayNameFor(model=>model.rating)
@DisplayFor(model=>model.rating)
@DisplayNameFor(model=>model.times)
@DisplayFor(model=>model.times)
@DisplayNameFor(model=>model.fave)
@DisplayFor(model=>model.fave)
@DisplayNameFor(model=>model.rated)
@DisplayFor(model=>model.rated)
@使用(Html.BeginForm()){
|
@ActionLink(“返回列表”、“索引”)
}
你要在GET和POST上删除医生?你的视图是什么样的?我在问题的底部添加了删除视图。