通过Javavscript将DatePicker值传递给C#控制器
Passing DatePicker value via Javavscript to C# Controller
我有一个引导数据选择器,我需要使用javascript将值传递给控制器中的C#代码。我知道如何用javascript调用控制器内部的函数,但我不确定如何传递日期选择器的值。这一切都需要点击一下按钮。这是我的日期选择器的代码:
<div class="row spiff-datepicksection">
<div class="col-lg-6 pull-right">
<div class="col-sm-5 col-lg-offset-4">
<div class="form-group">
<div class="input-group date">
<input id="datetimepicker1" type="text" class="form-control" id="startDate" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class="col-lg-3">
<input class="spiffdate-btn" type="submit" value="Submit" />
</div>
</div>
</div>
这是我的javascript:
<script>
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
var wrongid = $('.tab-content .active').attr('id');
$('a[data-toggle="tab"]').removeClass("active");
$(this).addClass("active");
var correctid = $(this).data("id");
alert($('.tab-content .active')[0].outerHTML);
if (correctid == "delayedspiff")
$.get("@Url.Action("DelayedSpiffDate", "Dashboard")");
else
$.get("@Url.Action("InstantSpiffDate", "Dashboard")");
});
</script>
这是我的控制器:
public ActionResult DelayedSpiffDate(DateTime startDate)
{
var available = _appService.GetFeatureStatus(1, "spiffDashboard");
if (!available)
return RedirectToAction("DatabaseDown", "Error", new { area = "" });
var acctId = User.AccountID;
startDate = DateTime.Today.AddDays(-6); // -6
var endDate = DateTime.Today.AddDays(1); // 1
Dictionary<DateTime, List<SpiffSummaryModel>> dict = new Dictionary<DateTime, List<SpiffSummaryModel>>();
try
{
var properties = new Dictionary<string, string>
{
{ "Type", "DelayedSpiff" }
};
telemetry.TrackEvent("Dashboard", properties);
dict = _reportingService.GetDailyDelayedSpiffSummaries(acctId, startDate, endDate);
}
catch (Exception e)
{
if (e.InnerException is SqlException && e.InnerException.Message.StartsWith("Timeout expired"))
{
throw new TimeoutException("Database connection timeout");
}
var error = _errorCodeMethods.GetErrorModelByTcError(PROJID.ToString("000") + PROCID.ToString("00") + "001", "Exception Getting DelayedSpiff Dashboard View", PROJID, PROCID);
error.ErrorTrace = e.ToString();
_errorLogMethods.LogError(error);
return RedirectToAction("index", "error", new { error = error.MaskMessage });
}
var spiffDateModels = new List<DelayedSpiffDateModel>();
foreach (var entry in dict)
{
var spiffDateModel = new DelayedSpiffDateModel();
spiffDateModel.Date = entry.Key;
spiffDateModel.Carriers = new List<DelayedSpiffCarrierModel>();
foreach (var item in entry.Value)
{
var spiffCarrierModel = new DelayedSpiffCarrierModel();
spiffCarrierModel.Carrier = item.CarrierName;
spiffCarrierModel.CarrierId = item.CarrierId;
spiffCarrierModel.ApprovedSpiffTotal = item.ApprovedSpiffTotal;
spiffCarrierModel.EligibleActivationCount = item.EligibleActivationCount;
spiffCarrierModel.IneligibleActivationCount = item.IneligibleActivationCount;
spiffCarrierModel.PotentialSpiffTotal = item.PotentialSpiffTotal;
spiffCarrierModel.SubmittedActivationCount = item.SubmittedActivationCount;
spiffCarrierModel.UnpaidSpiffTotal = item.UnpaidSpiffTotal;
spiffDateModel.Carriers.Add(spiffCarrierModel);
}
spiffDateModels.Add(spiffDateModel);
}
spiffDateModels = spiffDateModels.OrderByDescending(x => x.Date).ToList();
return PartialView(spiffDateModels);
}
目前startdate设置为datetime.today。我需要它从日期选择器中获取日期。如果需要任何进一步的信息,请告诉我。谢谢
在您的javascript中,添加此行以获取日期选择器文本框的值(顺便说一句,您的日期选择器上有两个id属性):
var startDate = $('#startDate').val();
然后把它和你的$一起传递。得到这样的电话:
$.get('@Url.Action("DelayedSpiffDate", "Dashboard")', { startDate: startDate });
相关文章:
- 如何将输入范围的值传递给JS中的变量
- 如何将值传递给wicket中的javascript函数
- 将值传递给jquery创建的输入字段
- 需要将select标记选项值传递给ajax函数
- 使用Ajax将PHP值传递给javascript
- 将javascript值传递给PHP
- 将javascript值传递给php是正确的方法
- 将不属于表单的HTML页面中的值传递给php页面
- Angular,将文本框的动态值传给控制器
- 在key up函数上将文本框值传递给javascript
- 可以't使用ajax调用将值传递给Web服务
- 如何在同一页面上使用windows.location.href将js值传递给php时停止刷新页面
- 将javascript返回值传递给MVC 4中的控制器
- 如何将JS函数中的值传递给laravel控制器
- JSON将null值传递给IE9中的MVC 4控制器
- 无法使用ajax将值传递给Codeigniter控制器
- 在jquerymobile中使用ajax将值传递给codeigniter中的控制器
- 通过Javavscript将DatePicker值传递给C#控制器
- 将ext文本框值传递给javascript,然后传递给控制器动作
- 将多个文本框的值传递给CodeIgniter中的控制器