在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);
}
});
- 3 回答
- 0 关注
- 853 浏览
添加回答
举报
0/150
提交
取消