为什么我的编辑器没有预先填充?

时间:2017-02-25 22:57:27

标签: asp.net-mvc

在我的一个程序中,我设置了一个“编辑”视图/动作方法,这个方法允许我编辑特定表条目的信息。编辑器选项有效,但不会使用当前信息填充编辑器。这导致“编辑”选项看起来与我的“创建”选项相同,这意味着允许用户创建新条目。

有什么我想念的吗?该视图的代码似乎与我所遵循的教程几乎相同,但它们显示的结果是您对“编辑”选项的期望;一个编辑器预先填充了条目的当前信息。

以下是我的观点和操作方法的代码。提前谢谢。

查看:

@model PharmTrack.Models.Doctor

@{
ViewBag.Title = "Edit";
Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Edit</h2>

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

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

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

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

行动方法:

    public ActionResult Edit(int id)
    {
        return View();
    }

1 个答案:

答案 0 :(得分:1)

您需要将要编辑的对象的数据放入模型类的实例中,并将其提供给View。

这样的代码:

public Rectangle[] latter= {
  new Rectangle(1120,560,35,101), 
  new Rectangle(100,450,35,101), 
  new Rectangle(400,340,35,101),
  new Rectangle(20,340,35,101), 
  new Rectangle(800,230,35,101), 
  new Rectangle(100,230,35,101), 
  new Rectangle(600,450,35,101), 
  new Rectangle(100,230,35,101), 
  new Rectangle(700,120,35,101)
};