2014-02-07 33 views
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">&times;</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函數中引用的模型?

+0

你不發送您的阿賈克斯後的任何數據。 – Saravana

+0

@Saravana,我在Url.Action聲明中傳遞模型。該模型的值不是某些字段的默認值,所以有數據被傳遞。有沒有更好的方法來傳遞這些數據? –

+0

您現在正在做的事情將嘗試添加模型屬性作爲路由值並將它們作爲查詢字符串值追加到URL中。它會*不*發佈它們。看看頁面上呈現的JQuery來理解爲什麼。 POST數據不會在URL中發送。 –

回答

1

感謝您對AntP的評論,因爲這是我需要知道要尋找什麼的區別。那到底工作魔術隊改變了jQuery所以它並沒有完全依賴於URL字符串,但在更多的傳統意義上的jQuery數據實際傳遞:

//modal button click events to update/check measure values 
$('#updateMeasures').click(function() { 
    $.ajax({ 
     url: '@Url.Action("UpdateScoring", "SendingReport")', 
     data: $('form').serialize(), 
     type: 'POST' 
     }) 
    }) 
$('#checkMeasures').click(function() { 
    $.ajax({ 
     url: '@Url.Action("CheckScoring", "SendingReport")', 
     data: $('form').serialize(), 
     type: 'POST' 
    }) 
})