我想創建asp.net mvc應用程序。在worker.cs類中,我添加了這些參數:Asp.net mvc計算字段編輯形式
public class Worker
{
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public double Net { get; set; }
[Editable(false)][NotMapped]
public double Gross
{
get {
if (Net <= 282.10 && Net > 0)
return Math.Round(Net/0.91, 2);
else if (Net <= 335.30 && Net > 282.10)
return Math.Round((Net - 46.5)/0.76, 2);
else if (Net <= 760 && Net > 335.3)
return Math.Round((Net - 75)/0.685, 2);
else if (Net > 760)
return Math.Round((Net/0.76), 2);
else
return 0;
}
}
}
總參數應該只讀。我的問題是關於編輯窗體,我需要顯示總數價值然後用戶類型淨值(實時)。我試圖使用knockout.js,但我不知道如何做到這一點。
div class="form-group">
@Html.LabelFor(model => model.Net, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Net, new { htmlAttributes = new { @class = "form-control", data_bind = "value: NetV, valueUpdate:'afterkeydown'" } })
@Html.ValidationMessageFor(model => model.Net, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Gross, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.Gross, new { @class = "form-control", data_bind="value:GrossV",@readonly = "readonly", disabled = "disabled" })
</div>
</div>
有沒有辦法從數據庫螞蟻顯示獲得淨值作爲默認的可觀察值? – Laurynas
@Laurynas從控制器傳遞簡單的值並使用@ Html.TextBoxFor(model => model.net,new {data_bind =「value:net」}); –
我已經使用這個設置:@ Html.EditorFor(model => model.Net,new {htmlAttributes = new {@class =「form-control」,data_bind =「value:net,valueUpdate:'afterkeydown'」}} ),everythink工作,但默認值顯示空的文本框 – Laurynas