0

我正在开发 MVC 应用程序。在视图中,我声明了一些变量,我想在 Jscript 中使用它。

    @model PaymentAdviceEntity.EMI
    @{
        ViewBag.Title = "Create";
        double TotalAmt = 0;

    }


    @using (Html.BeginForm("Edit", "EMI", FormMethod.Post, new { @id = "frmEdit" }))
    {
      @if (Model.EMI_Child.Count > 0)
     {
      @foreach (var PaidEMIList in Model.EMI_Child)
       {           
        TotalAmt = TotalAmt + PaidEMIList.Amount;
       }
     }              
   }


<script>
    $(document).ready(function () {
        CheckBalAmt();
     });

  function CheckBalAmt()
{

    var nTotalAmount = document.getElementById("TotalAmount").value;      
    var nAllreadyPaidAmount = document.getElementById("AllreadyPaidAmount").value;    
    var BalAmt = nTotalAmount - nAllreadyPaidAmount;
    var totalAmt1 = @TotalAmt; <- Shows error here...
    var BalAndTotalAmt  = BalAmt +totalAmt1; 
   $('.BalanceAmt').text("Bal Amt. : " +  BalAndTotalAmt );
}

</script>

在上面的 CheckBalAmt() 方法中,我想显示变量 TotalAmt 的值......但它没有显示任何东西......

4

2 回答 2

0
var totalAmt1 = ('@TotalAmt');
var BalAndTotalAmt  = BalAmt - totalAmt1;
alert(@TotalAmt);
$('.BalanceAmt').text("Bal Amt. : " +  BalAndTotalAmt );

此代码有效...

于 2013-07-29T06:18:57.113 回答
-1
    function CheckBalAmt()
    {

       alert('@TotalAmt');

    }

你必须使用剃刀符号

于 2013-07-29T05:38:34.953 回答