【发布时间】:2016-02-20 08:57:36
【问题描述】:
我有一个 ASP.net MVC 应用程序。它使用引导导航栏在两个表单之间导航。我将日期从日期选择器传递给 C# 函数,但如果没有在日期选择器中输入日期,它在页面加载时不起作用。如果没有日期可以通过,我不确定如何补偿。如果日期选择器中没有日期,则应采用今天的日期。我没有收到错误消息,它只是不起作用。这是我的看法:
<div class="row-fluid 1">
<div class="col-lg-12 delayed_spiff_body">
<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 type="text" id="startDate" class="form-control" />
<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="button" value="Submit" />
</div>
</div>
</div>
<div class="row spiff_tabs_body">
<!-- Nav tabs -->
<ul class="nav nav-tabs spiff_tabs" role="tablist">
<li role="presentation" class="active">
<a href="#home" aria-controls="home" role="tab" data-id="delayedspiff" data-toggle="tab" onclick="FormGet('dashboard/delayedspiff', 'delayedspiff')">Potential Spiff</a>
</li>
<li role="presentation">
<a href="#profile" aria-controls="profile" role="tab" data-id="instantspiff" data-toggle="tab" onclick="FormGet('dashboard/instantspiff', 'delayedspiff')">Instant Spiff</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="delayedspiff"></div>
<div role="tabpanel" class="tab-pane" id="instantspiff"></div>
</div>
</div>
</div>
</div>
<script>
$(function () {
FormGet('dashboard/delayedspiff', 'delayedspiff');
});
</script>
<script>
$(".spiffdate-btn").click(function(){
var correctId = $("ul.spiff_tabs li.active a").attr('data-id');
console.log(correctId);
var startDate = $("#startDate").val();
if (startDate == "") {
} else {
if (correctId == "delayedspiff")
{
$.get("@Url.Action("DelayedSpiff", "Dashboard")", { startDate: startDate });
} else if (correctId = "instantspiff") {
$.get("@Url.Action("InstantSpiffDate", "Dashboard")", { startDate: startDate });
}
}
});
</script>
这是我的控制器中的部分代码,应该将日期传递给它。
public ActionResult DelayedSpiff(DateTime startDate)
{
var available = _appService.GetFeatureStatus(1, "spiffDashboard");
if (!available)
return RedirectToAction("DatabaseDown", "Error", new { area = "" });
//var startDate = DateTime.Today.AddDays(-6);
if (startDate == DateTime.MinValue)
{
startDate = DateTime.Today.AddDays(-6);
}
else
{
startDate = startDate.AddDays(-7);
}
var acctId = User.AccountID;
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);
谁能告诉我我做错了什么?我猜它与 FormGet 函数有关。谢谢。
【问题讨论】:
标签: jquery asp.net asp.net-mvc twitter-bootstrap datepicker