Asp.net mvc 如何在ASP.NET MVC中减去2个值
我想减去2个值,并在索引中显示结果 AmountOfRent是AmountOfRent,用户将在Crete中输入收据,因此当返回索引时,余额将显示 这是我的控制器:Asp.net mvc 如何在ASP.NET MVC中减去2个值,asp.net-mvc,Asp.net Mvc,我想减去2个值,并在索引中显示结果 AmountOfRent是AmountOfRent,用户将在Crete中输入收据,因此当返回索引时,余额将显示 这是我的控制器: [HttpPost] public ActionResult Index(ContractMonth am) { am.Balance = am.contracts.AmountOfRent - am.Receipt; return View(am); } 这是
[HttpPost]
public ActionResult Index(ContractMonth am)
{
am.Balance = am.contracts.AmountOfRent - am.Receipt;
return View(am);
}
这是一种观点:
@DisplayNameFor(model=>model.Monthe)
@DisplayNameFor(model=>model.receive)
@DisplayNameFor(model=>model.Balance)
@DisplayNameFor(model=>model.ContractsId)
@foreach(模型中的var项目){
@DisplayFor(modelItem=>item.Monthe)
@DisplayFor(modeleItem=>item.contracts.AmountOfRent)
@DisplayFor(modelItem=>item.Receive)
@DisplayFor(modelItem=>item.Balance)
@DisplayFor(modelItem=>item.contracts.contracts\u Num)
}
如果您只想减去两个数字并在视图中显示结果,您可以在razor视图中这样做
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Monthe)
</th>
<th>
@Html.DisplayNameFor(model => model.Receipt)
</th>
<th>
@Html.DisplayNameFor(model => model.Balance)
</th>
<th>
@Html.DisplayNameFor(model => model.ContractsId)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Monthe)
</td>
<td>
@{ var reuslt=item.contracts.AmountOfRent-item.Receipt;}
@result
</td>
<td>
@Html.DisplayFor(modelItem => item.Receipt)
</td>
<td>
@item.AmountOfRent - item.Receipt
</td>
<td>
@Html.DisplayFor(modelItem => item.contracts.Contract_Num)
</td>
</tr>
}
</table>
@DisplayNameFor(model=>model.Monthe)
@DisplayNameFor(model=>model.receive)
@DisplayNameFor(model=>model.Balance)
@DisplayNameFor(model=>model.ContractsId)
@foreach(模型中的var项目){
@DisplayFor(modelItem=>item.Monthe)
@{var reuslt=item.contracts.AmountOfRent item.Receipt;}
@结果
@DisplayFor(modelItem=>item.Receive)
@item.AmountOfRent-item.Receipt
@DisplayFor(modelItem=>item.contracts.contracts\u Num)
}
哪件事阻止了你?出现了错误,而且还没有出现,所以我认为当我添加@using(Html.BeginForm(“Index”,“Home”,FormMethod.Post))时可能是错误的,因为我有Get Index,Post IndexParser error这是错误的名称