为什么我无法在另一个页面上看到我选择的信息?

时间:2016-09-03 12:00:16

标签: c# html asp.net-mvc razor view

我正在处理一本简单的电话簿,而我正试图删除一个联系人。当用户按下左图上的删除时,它的信息不会被显示(右图)

enter image description here

这是我在控制器中的代码

[HttpPost]
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 Project1.Models.EF_Model.Phone_book

@{
    ViewBag.Title = "Delete";
}

<h2>Delete</h2>

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

        <dd>
            @Html.DisplayFor(m => m.Id)
        </dd>

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

1 个答案:

答案 0 :(得分:1)

您没有将任何模型返回到视图。

 return View(); <--- model is missing.

应该是

 var model = _someRepository.LoadPhoneBook(id);
 return View(model);