输入字段未在ajax函数中更新

时间:2012-10-26 21:48:37

标签: c# jquery ajax

我会尝试解释我面临的最佳问题

我有一个视图,里面有一个局部视图,它基本上显示一个输入字段和一个按钮。这个局部视图看起来像这样

<fieldset>
    @Html.HiddenFor(model => model.AuctionId)
    @Html.HiddenFor(model => model.AuctionEventId)
     <div class="lotdetail-maxbid-row">
        @Html.TextBoxFor(model => model.Amount, new { @class = "radius2 text-box single-line valid" })
        @Html.ValidationMessageFor(model => model.Amount)
    </div>
    <input type="submit" id="autobidButton" value="Increase Max bid" class="btn btn-level2 btn-maxbid @disableButton" />
</fieldset>

在这个局部视图中,我已经放了这个脚本

<script type="text/javascript">
$(document).ready(function () {
    $('#autobidButton').click(function () {
        $.ajax({
            url: "/Lot/AutobidConfirmationPartial",
            data: {
                amount: $("#Amount").val(),
                auctionEventId: $("#AuctionEventId").val(),
                auctionId: $("#AuctionId").val()
            },
            success: function (result) {
                $("#autobidConfirmation").empty().append(result);
            },
            type: "POST"
        });
        return false;
    });
});
</script>

意图加载结果,这是父页面中div的局部视图。

问题是金额始终为0(默认值),并且在调用脚本中的函数时永远不会更新。

知道该做什么或看什么?

谢谢,

更新:这是生成的html和控制器方法

<fieldset>
   <input id="AuctionId" type="hidden" value="3" name="AuctionId">
   <input id="AuctionEventId" type="hidden" value="1" name="AuctionEventId">
   <div class="lotdetail-maxbid-row">
      <input id="Amount" class="radius2 text-box single-line valid" type="text" value="0" name="Amount">
   </div>
  <input id="autobidButton" class="btn btn-level2 btn-maxbid " type="submit" value="Increase Max bid">
</fieldset>

public ActionResult AutobidConfirmationPartial(int auctionEventId, int auctionId, decimal amount)
    {
        var incorrectAmount = false;
        var correctedAmount = amount;
        if (!CheckMaxBidFitsIncrementTier(amount, auctionEventId))
        {
            incorrectAmount = true;
            correctedAmount = CalculateNextBidAmountForWrongMaxAmount(amount, auctionEventId); ;
        }

        var model = new BidOnAuctionViewModel
        {
            AuctionEventId = auctionEventId,
            AuctionId = auctionId,
            Amount = correctedAmount,
            IncorrectAmount = incorrectAmount,
        };
        //TotalPriceBreakdown(ref model, null);
        return PartialView("BidConfirmationPartial", model);
}

0 个答案:

没有答案