看不到我的记录信息在我看来

问题描述:

我正在tryng删除一条记录(这是一个简单的电话簿项目),并显示在确认页面的数据,但现在看起来这看不到我的记录信息在我看来

How can i fill the blanks

这是我家控制器

#region [- Get -] 

    [HttpGet] 
    // [HttpDelete] 
    public ActionResult Delete(int? _id, Models.EF_Model.Phone_book _model) 
    { 
     return View(); 
    } 
    #endregion 

    #region [- Post -] 

    [HttpPost] 
    //[HttpDelete] 
    public ActionResult Delete(Models.EF_Model.Phone_book _Model) 
    { 
     if (ModelState.IsValid) 
     { 
      Ref_ViewModel = new ViewModel.ViewModel(); 
      Ref_ViewModel.Delete(_Model.Id); 
     } 
     else 
     { 
      ViewBag.Massage = "Choose a Contact"; 
     } 
     return View(_Model); 
    } 
    #endregion 
    #endregion 

这是它的视图

@model Phone_Book.Models.EF_Model.Phone_book 

@{ 
    ViewBag.Title = "Delete"; 
} 

<h2>Delete</h2> 

<h3>Are you sure you want to delete this?</h3> 
<div> 
    <h4>Phone_book</h4> 
    <hr /> 
    <dl class="dl-horizontal"> 
     <dt> 
      @Html.DisplayNameFor(model => model.First_Name) 
     </dt> 

     <dd> 
      @Html.DisplayFor(model => model.First_Name) 
     </dd> 

     <dt> 
      @Html.DisplayNameFor(model => model.Last_Name) 
     </dt> 

     <dd> 
      @Html.DisplayFor(model => model.Last_Name) 
     </dd> 

     <dt> 
      @Html.DisplayNameFor(model => model.Number) 
     </dt> 

     <dd> 
      @Html.DisplayFor(model => model.Number) 
     </dd> 

     <dt> 
      @Html.DisplayNameFor(model => model.Email) 
     </dt> 

     <dd> 
      @Html.DisplayFor(model => model.Email) 
     </dd> 

     <dt> 
      @Html.DisplayNameFor(model => model.Address) 
     </dt> 

     <dd> 
      @Html.DisplayFor(model => model.Address) 
     </dd> 

    </dl> 

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

     <div class="form-actions no-color"> 
      <input type="submit" value="Delete" class="btn btn-default" /> | 
      @Html.ActionLink("Back to List", "Index") 
     </div> 
    } 
</div> 

我试图解决这个由我自己,但想不到任何东西

我怎样才能填补空白?

问题是,你从你的控制器没有发送任何东西到你的视图。

您应该根据您的ID找到您的联系人。完成后,检查它是否为空并将其发送到您的视图。

[HttpGet] 
public ActionResult Delete(int? id) 
{ 
    if (id == null) 
    { 
     return new HttpStatusCodeResult(HttpStatusCode.BadRequest); 
    } 
    Phone_Book.Models.EF_Model.Phone_book‌ contact = Context.Phone_book.Select(_id); 
    if (contact == null) 
    { 
     return HttpNotFound(); 
    } 
    return View(contact); 
} 

你不发送模型到视图的一个实例:

public ActionResult Delete(int? _id, Models.EF_Model.Phone_book _model) 
{ 
    return View(); 
} 

所以没有什么可以显示。通常我不会怀疑这个行为是以模型的一个实例作为参数。当你调试这个时,_model是否有你正在寻找的实例?如果是这样,它传递给视图:

return View(_model); 

如果没有,你可以使用_id从数据源中查找模式并传递给视图:

var model = **query your DB here**; 
return View(model); 

(如果连_id没有填充任何有用的东西,那么它听起来像你会有另一个问题在其他地方也要解决)