更新 - 数据库不起作用

时间:2016-12-19 22:36:30

标签: asp.net-mvc

我将数据注释添加到PurchaseAmount字段[ReadOnly(true)]

构建应用程序,在程序包管理器中运行“Add-Migration New 1”,

然后运行“Update-Database”

没有任何改变。页面上的字段仍然可以编辑。

你能帮忙吗?

型号代码

public class Investments
{
    public int ID { get; set; }
    ....
    [ReadOnly(true)]
    [DataType(DataType.Currency)]
    public double PurchaseAmount { get; set; }
}

控制器代码

@model StockHoldings.Models.Investments
....
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    ....
    <div class="form-group">
        @Html.LabelFor(model => model.PurchaseAmount, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.TextBoxFor(model => model.PurchaseAmount, new { id = "purchaseamountID", name = "PurchaseAmount", htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.PurchaseAmount, "", new { @class = "text-danger" })
        </div>
    </div>
    ....
}

0 个答案:

没有答案