我有一个用于选择日期的文本框, Razor 页面中有一个操作链接可以重定向到另一个页面,其中日期值作为参数之一。 每当用户更改日期时,有什么方法可以动态更改 actionlink 的值。 我的 Razor View 就像
<div class="col-md-4">
@Html.TextBoxFor(model => model.Date, new { @class = "datepicker form-control" })
@Html.ValidationMessageFor(model => model.Date)
</div>
@Html.ActionLink("Mark Attendance", "Add", "Attendance", new { @id = @model.ClassId }, new { @class = " btn btn-primary"})
在 Javascript 中我已经能够做到
$("#Date").datepicker({
showOn: 'both',
altFormat: 'MM-dd-yy',
dateFormat: 'MM-dd-yy',
changeMonth: true,
changeYear: true,
yearRange: "1900:2050"
})
.change(dateChanged)
.on('changeDate', dateChanged);
function dateChanged(ev) {
//How can i change the action link in a way that add an extra param date with selected value ?
}
有什么办法吗?
最佳答案
您可以使用 javascript 更改日期的值
$('.btn btn-primary').attr('href', function () {
return this.href.replace('_Parameter1', Date_Value);
});
在 View 中:-
@Html.ActionLink("Mark Attendance", "Add", "Attendance", new { @id = @model.ClassId,Parameter1='_Parameter1'}, new { @class = " btn btn-primary"})
在 Controller 中:-
public ActionResult Add(int ID, DateTime date)
关于javascript - 从 Javascript 更改 Actionlink 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26813796/