我将尝试以最佳方式解释我面临的问题
我有一个视图,里面有一个局部视图,它基本上显示一个输入字段和一个按钮。这个局部视图看起来像这样
<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);
}