我想减去2个值并在索引中显示结果。
AmountOfRent是AmountOfRent,并且用户将在Crete中输入收据,因此当返回索引时,余额将显示
这是我的控制器:
<tr>
<td width="250" align="center" style="background:#F63"><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onSubmit="return confirm ('ACTUALIZE sort_price in EUR ?')">
<input type="submit" name="sort_price_act" value="SORT NEW PRICE">
</form>
</td>
</tr>
这是视图:
[HttpPost]
public ActionResult Index(ContractMonth am)
{
am.Balance = am.contracts.AmountOfRent - am.Receipt;
return View(am);
}
答案 0 :(得分:1)
如果您只想减去两个数字并在视图中显示结果,则可以在剃刀视图中执行此操作。
<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>