我有一个新的开发任务,我正在尝试做报告仪表板,我的要求是 我将有一个表单,我需要从表单中选择值,并根据用户选择我需要在同一页面中显示高图表和同一页面中我的数据的表格视图。所以我的表单内容是静态的,我的Highcharts数据和表格包含动态数据。
到目前为止我已经完成的步骤:
登录表单,如果凭据有效,请显示我的mainform.aspx 我的mainform.aspx使用提交按钮进行表单
<form id="StatsForm" name="StatsForm" action="../Stats/Index/" method="POST"
enctype="multipart/form-data">
<%= Html.AntiForgeryToken()%>
<% Html.RenderPartial("OptionalFields"); %>
</form>
点击按钮我将表单数据发送到控制器 //
$(document).ready(function () {
$("#GetReport").click(function () {
$("form[name=StatsForm]").submit();
});
});
//]]>
</script>
我正在控制器操作中从表单数据中执行一些存储库功能,并且我将表单值添加到模型类中。
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(FormCollection form)
{
var manufacturerId = Convert.ToInt32(form["manufacturerId"]);
var reportId = Convert.ToInt32(form["reportId"]);
var categoryId = Convert.ToInt32(form["categoryId"]);
var retailerId = Convert.ToInt32(form["retailerId"]);
var countryId = Convert.ToInt32(form["countryId"]);
var regionId = Convert.ToInt32(form["regionId"]);
var manufacturerWidgetId = (form["ManufacturerWidgetId"]);
var startDate = new DateTime(1, 1, 1, 0, 0, 0, 0);
var endDate = new DateTime(1, 1, 1, 0, 0, 0, 0);
if (!String.IsNullOrEmpty(form["StartDate"]))
{
startDate = Convert.ToDateTime(form["StartDate"]);
}
if (!String.IsNullOrEmpty(form["EndDate"]))
{
endDate = Convert.ToDateTime(form["EndDate"]);
}
var reportName = _reportRepository.GetReport(reportId);
var stats = new Stats
{
ManufacturerId = manufacturerId,
CountryId = countryId,
ReportName = reportName.ToString(),
StartDate = startDate,
EndDate = endDate
};
现在我很震惊,我做了以下步骤,不确定我是否正确。我想因为我的mainform.aspx必须显示动态部分我试图创建部分foreach报告和选择uservalue我打算在mainform.aspx中注入相应的部分。
我正在做的事情:(继续我的Action方法)
switch (reportName.Code)
{
case "INTER":
return RedirectToAction("InterStats",
new
{
manufacturerId = manufacturerId,
countryId = countryId,
startDate = "2013-01-01",
endDate = "2013-01-31"
});
break;
case "CUMLEADS":
return RedirectToAction("ParametersCumLeads",
new
{
manufacturerId = manufacturerId,
countryId = countryId,
categoryId = categoryId,
startDate = startDate.ToString("yyyy-MM-dd"),
endDate = endDate.ToString("yyyy-MM-dd")
});
break;
case "IMP":
break;
}
5.我的部分观点:
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
public JsonResult InterStats(int manufacturerId, int countryId, DateTime startDate, DateTime endDate)
{
//Get all manufacturerwidgets for manufacturer
var manufacturerWidget = _manufacturerWidgetsRepository.GetManufacturerWidgetByManufacturerAndCountry(manufacturerId, countryId);
var interReport = new InterReport();
var interRecordList = new List<InterRecord>(); // a list of my anonymous type without the relationships
interReport.InterRecordList = new List<InterRecord>();
var count = 1;
foreach (var mw in manufacturerWidget)
{
var widgetName = mw.Description;
//Get the product stats data
var imps = _productStatsRepository.GetSumImpressionsProductStatsForManufacturerCountryDate(
mw.Id, countryId, startDate, endDate);
var clicks = _productStatsRepository.GetSumClicksProductStatsForManufacturerCountryDate(
mw.Id, countryId, startDate, endDate);
float ctr = 0;
if (imps != 0 && clicks != 0)
{
ctr = ((clicks / (float)imps) * 100);
}
// Create the data for the report
var interRecord = new InterRecord
{
WidgetName = widgetName,
Impressions = imps,
Interactions = clicks,
Ctr = ctr,
Count = count
};
interReport.InterRecordList.Add(interRecord);
count++;
}
interReport.Counter = count;
return Json(interReport, JsonRequestBehavior.AllowGet);
}
我尝试在我的mainform.aspx中编写一个小的ajax函数来渲染部分数据,但$(“#GetReport”)。click(function()我发送表单回到控制器不知道怎么回事会再来一次吗?
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function () {
$("#GetReport").click(function () {
$.ajax({
url: "/Stats/InterStats/<%: Model.ManufacturerId %>/<%: Model.CountryId %>/<%: Model.StartDate %>/<%: Model.EndDate %>",
type: 'get',
success: function (data) {
<% Html.RenderPartial("InterStats"); %>
}
});
$("form[name=StatsForm]").submit();
});
});
//]]>
</script>
所以我的部分观点,我的数据准备就绪,我无法在mianform.aspx中显示相应的部分内容。请帮助我该怎么做?
答案 0 :(得分:1)
$.ajax({
url: "/Stats/InterStats/<%: Model.ManufacturerId %>/<%: Model.CountryId %>/<%: Model.StartDate %>/<%: Model.EndDate %>",
type: 'get',
success: function (data) {
<% Html.RenderPartial("InterStats"); %>
}
});
而不是这个,你需要在success
函数中使用一些javascript来处理响应。可能类似于:
success: function (data) {
$('#someDivId').html(data);
}