I added the data annotation to the PurchaseAmount
field [ReadOnly(true)]
,
Built the application, ran "Add-Migration New 1" in Package Manager,
then ran "Update-Database"
Nothing changed. The field on the page was still editable.
Can you help?
Model code
public class Investments
{
public int ID { get; set; }
....
[ReadOnly(true)]
[DataType(DataType.Currency)]
public double PurchaseAmount { get; set; }
}
Controller Code
@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>
....
}