亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用jquery或ajax為MVC項目更新c#/ asp.net中的razor部分視圖

如何使用jquery或ajax為MVC項目更新c#/ asp.net中的razor部分視圖

偶然的你 2019-10-18 10:56:22
在MVC部分視圖文件中,我構建了一個Html.TextBox和兩個提交按鈕。單擊這兩個按鈕將增加/減少Html.TextBox值。Html.TextBox顯示的值將相應地更改。但是,一旦我需要單擊后根據新值更新#refTable div。頁面或部分從未更新。下面是代碼,其中添加了一些注釋以用于說明。謝謝你的幫助。// * ** * *** cshtml文件 ** * ** * **** //<body></body><input type="submit" value="PrevY" name="chgYr2" id="pY" />@{    var tempItem3 = Model.First(); // just give the first entry from a database, works.    if (ViewData["curSel"] == null)    {    @Html.TextBox("yearSelect3", Convert.ToDateTime(tempItem3.Holiday_date).Year.ToString());      ViewBag.selYear = Convert.ToDateTime(tempItem3.Holiday_date).Year; // just initial value, works    ViewData["curSel"] = Convert.ToDateTime(tempItem3.Holiday_date).Year;    }    else    {    @Html.TextBox("yearSelect3", ViewData["curSel"].ToString());    } }<input type="submit" value="NextY" name="chgYr2" id="nY" /><script type="text/javascript">    $(document).ready(function () {        $(document).on("click", "#nY", function () {            var val = $('#yearSelect3').val();            $('#yearSelect3').val((val * 1) + 1);            var dataToSend = {                id: ((val * 1) + 1)            }            // add some jquery or ajax codes to update the #refTable div            // also ViewBag.selYear need to be updated as ((val * 1) + 1)            // like:   ViewBag.selYear = ((val * 1) + 1);            // any similar temp variable is fine        });        });        $(document).on("click", "#pY", function () {            var val = $('#yearSelect3').val();            $('#yearSelect3').val((val * 1) - 1);            var dataToSend = {                id: ((val * 1) - 1)            }        });    });</script><span style="float: right"><a href="/">Set Holiday Calender for 2013</a></span><span id="btnAddHoliday">@Html.ActionLink("Add Holiday", "Create", null, new { id = "addHilBtn" })</span>    </table></div>
查看完整描述

3 回答

?
慕沐林林

TA貢獻2016條經驗 獲得超9個贊

您也可以像這樣使用Url.Action作為路徑:


$.ajax({

        url: "@Url.Action("Holiday", "Calendar", new { area = "", year= (val * 1) + 1 })",                

        type: "GET",           

        success: function (partialViewResult) {            

            $("#refTable").html(partialViewResult);

        }

    });


查看完整回答
反對 回復 2019-10-18
  • 3 回答
  • 0 關注
  • 891 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號