我的cshtml中有两行显示金额值。我需要实现的业务规则是,如果两个数量相等,则只需要显示一行。我写了一段代码,但不知道如何让它工作。
$(function ShowHideRow () {
var cashAvailbleToInvestInFunds = $('#trCashAvailableToInvestInFunds').val;
var cashAvailbleToInvestInEquities = $('#trCashAvailableToInvestInEquities').val;
if (cashAvailbleToInvestInFunds == cashAvailbleToInvestInEquities)
$('#trCashAvailableToInvestInEquities').hide();
});
<tr id="trCashAvailableToInvestInFunds" >
<td>Available cash to Invest in funds at @date_request</td>
<td>@Model.CashAvailableToInvest.ToString("C")</td>
</tr>
<tr id="trCashAvailableToInvestInEquities">
<td>Available cash to Invest in equities at @date_request</td>
<td>@Model.CashAvailableToInvestInEquities.ToString("C")</td>
</tr>
我尝试在DocumentReady上编写逻辑,但是因为函数会在内容加载之前触发,因此无法工作。有人可以告诉我我该怎么做。
答案 0 :(得分:2)
我会在Razor视图中这样做:
<tr id="trCashAvailableToInvestInFunds" >
<td>Available cash to Invest in funds at @date_request</td>
<td>@Model.CashAvailableToInvest.ToString("C")</td>
</tr>
@if(Model.CashAvailableToInvestInEquities != Model.CashAvailableToInvest)
{
<tr id="trCashAvailableToInvestInEquities">
<td>Available cash to Invest in equities at @date_request</td>
<td>@Model.CashAvailableToInvestInEquities.ToString("C")</td>
</tr>
}