我的控制器中有一个函数,它接收两个日期,如果我传递参数硬编码我的问题,我可以解决如何从我的文本字段中获取值并将它们传递给函数,我不想使用表单,我的cshtml代码是:
<div class="col-lg-12">
<div class="col-md-2">
<div class="input-field">
<input asp-for="StartDate" type="text" class="datepicker" autocomplete="off" id="sDate">
<span asp-validation-for="StartDate"></span>
<label class="active" for="StartDate">Inicio</label>
</div>
</div>
<div class="col-md-2">
<div class="input-field">
<input asp-for="EndDate" type="text" class="datepicker" autocomplete="off" id="eDate">
<span asp-validation-for="EndDate"></span>
<label class="active" for="EndDate">Termina</label>
</div>
</div>
<div class="col-md-2" id="btnsBuscar">
<div class="actions clearfix mt-35 text-right">
<a id="btnVid" href="#" data-ajax="true" data-ajax-method="POST" data-ajax-url="@Url.Action("VideosClientReport", "Report",new {Date1= StartDate", Date2="EndDate"})" data-ajax-begin="showLoader()" data-ajax-complete="hideLoader()" data-ajax-update="#content" class="active btn waves-effect waves-light pull-right ml-28">Buscar</a>
</div>
</div>
</div>
并且我也尝试使用此功能,但是我可以重新加载我的PartialView,就像上面的代码数据-ajax-update =&#34; #content&#34;功能是:
<script type="text/javascript">
$(function () {
$("#btnVid").click(function () {
var s = $('#sDate').val();
var e = $("#eDate").val();
alert(s + " " + e);
$.ajax({
type: "POST",
url: '@Url.Action("VideosClientReport", "Report")',
data: { StartDate: s, EndDate: e},
success: function (response) {
$("#content").load(response);
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
});
});
答案 0 :(得分:0)
Thanx to Shyju post我使用此代码解决了我的问题:
<script type="text/javascript">
$(function () {
$("#btnVid").click(function () {
var s = $('#sDate').val();
var e = $("#eDate").val();
$.ajax({
type: "POST",
url: '@Url.Action("VideosClientReport", "Report")',
data: { StartDate: s, EndDate: e},
success: function (response) {
$("#content").html(response);
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
});
});
</script>