我将数据注释添加到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>
....
}