我想创建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