0
我有與相關的jQuery ajax點擊調用的按鈕。被傳入的模型有一些填充的字段,但不是全部。剃刀視圖jQuery ajax調用 - 模型沒有完全填充
有問題的按鈕作爲部分的一部分包含在頁面中。該部分頁面看起來是這樣的:
<div class="modal fade" id="adjustScoreModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Adjust Scoring Values</h4>
</div>
<div class="modal-body">
<table>
@foreach (VIMS.Web.Models.Measure m in Model.list)
{
<tr>
<td>
@Html.HiddenFor(i => m.id)
@Html.LabelFor(i => m.measure) :
@Html.DisplayFor(i => m.measure)
</td>
<td colspan="2">
@Html.LabelFor(i => m.lastModified) :
@Html.DisplayFor(i => m.lastModified)
</td>
</tr>
<tr class="range">
<td>
@Html.LabelFor(i => m.weight)
<br />
@Html.TextBoxFor(i => m.weight)
</td>
<td>
@Html.LabelFor(i => m.zeroValue)
<br />
@Html.TextBoxFor(i => m.zeroValue)
</td>
<td>
@Html.LabelFor(i => m.hundredValue)
<br />
@Html.TextBoxFor(i => m.hundredValue)
</td>
</tr>
<tr class="range">
<td>
@Html.LabelFor(i => m.increment)
<br />
@Html.TextBoxFor(i => m.increment)
</td>
<td>
@Html.RadioButtonFor(i => m.rangeBased, "true", new { name=m.id.ToString()+ "Range"}) Range based incrememnt
</td>
<td>
@Html.RadioButtonFor(i => m.rangeBased, "false", new { name = m.id.ToString() + "Range" }) Always incremented
</td>
</tr>
<tr>
<td>
<hr />
</td>
</tr>
}
</table>
</div>
<div class="modal-footer">
<button type="button" id="updateMeasures" class="btn btn-default" data-dismiss="modal">SAVE</button>
<button type="button" id="checkMeasures" class="btn btn-default" data-dismiss="modal">Check Values</button>
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
jQuery的塊看起來是這樣的:
//modal button click events to update/check measure values
$('#updateMeasures').click(function() {
$.ajax({
url: '@Url.Action("UpdateScoring", "SendingReport", Model)',
type: 'POST'
})
})
$('#checkMeasures').click(function() {
$.ajax({
url: '@Url.Action("CheckScoring", "SendingReport", Model)',
type: 'POST'
})
})
在這裏傳遞的模型具有一定的填充性能而不是其他的。由於該模型似乎是上次發佈頁面時建立的,因此我懷疑它與URL建立有關。如何確保在頁面呈現時刷新ajax函數中引用的模型?
你不發送您的阿賈克斯後的任何數據。 – Saravana
@Saravana,我在Url.Action聲明中傳遞模型。該模型的值不是某些字段的默認值,所以有數據被傳遞。有沒有更好的方法來傳遞這些數據? –
您現在正在做的事情將嘗試添加模型屬性作爲路由值並將它們作爲查詢字符串值追加到URL中。它會*不*發佈它們。看看頁面上呈現的JQuery來理解爲什麼。 POST數據不會在URL中發送。 –