Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在asp.net mvc中添加报表参数_C#_Asp.net_Asp.net Mvc_Asp.net Mvc 3_Razor - Fatal编程技术网

C# 如何在asp.net mvc中添加报表参数

C# 如何在asp.net mvc中添加报表参数,c#,asp.net,asp.net-mvc,asp.net-mvc-3,razor,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 3,Razor,我在报告中添加了两个参数dtStartDate和dtEndDate。我正试图弄明白如何在控制器上实现。当前,在尝试设置参数时,它将抛出一个错误。请告知,谢谢 以下是迄今为止我掌握的代码: public ActionResult DetailsReport() { LocalReport localReport = new LocalReport(); localReport.ReportPath = Server.MapPath("~/Content/Reports/Data.

我在报告中添加了两个参数dtStartDate和dtEndDate。我正试图弄明白如何在控制器上实现。当前,在尝试设置参数时,它将抛出一个错误。请告知,谢谢

以下是迄今为止我掌握的代码:

public ActionResult DetailsReport()
{

    LocalReport localReport = new LocalReport();
    localReport.ReportPath = Server.MapPath("~/Content/Reports/Data.rdlc");

    ReportParameter param0 = new ReportParameter("dtStartDate", "2014-01-28");
    ReportParameter param1 = new ReportParameter("dtStartEnd", "2014-01-30");

    localReport.SetParameters(new ReportParameter[] { param0, param1 });
    ReportDataSource reportDataSource = new ReportDataSource("dsData", GetAllData());

    localReport.DataSources.Add(reportDataSource);
    string reportType = "PDF";
    string mimeType;
    string encoding;
    string fileNameExtension;

    //The DeviceInfo settings should be changed based on the reportType
    string deviceInfo =
    "<DeviceInfo>" +
    "  <OutputFormat>PDF</OutputFormat>" +
    "  <PageWidth>8.5in</PageWidth>" +
    "  <PageHeight>11in</PageHeight>" +
    "  <MarginTop>0.5in</MarginTop>" +
    "  <MarginLeft>1in</MarginLeft>" +
    "  <MarginRight>1in</MarginRight>" +
    "  <MarginBottom>0.5in</MarginBottom>" +
    "</DeviceInfo>";

    Warning[] warnings;
    string[] streams;
    byte[] renderedBytes;

    //Render the report
    renderedBytes = localReport.Render(
        reportType,
        deviceInfo,
        out mimeType,
        out encoding,
        out fileNameExtension,
        out streams,
        out warnings);
    Response.AddHeader("content-disposition", "attachment; filename=Data." + fileNameExtension);
    return File(renderedBytes, mimeType);


}

public static List<vwDataReport> GetAllData()
{
    var entities = new DataEntities();
    var x = from c in entities.vwDataReport
            select c;
    return x.ToList();
}
public ActionResult DetailsReport()
{
LocalReport LocalReport=新建LocalReport();
localReport.ReportPath=Server.MapPath(“~/Content/Reports/Data.rdlc”);
ReportParameter param0=新的ReportParameter(“dtStartDate”、“2014-01-28”);
ReportParameter param1=新的ReportParameter(“dtStartEnd”,“2014-01-30”);
SetParameters(新的ReportParameter[]{param0,param1});
ReportDataSource ReportDataSource=新的ReportDataSource(“dsData”,GetAllData());
localReport.DataSources.Add(reportDataSource);
string reportType=“PDF”;
字符串模拟类型;
字符串编码;
字符串文件名扩展名;
//应根据报告类型更改DeviceInfo设置
字符串设备信息=
"" +
“PDF”+
“8.5英寸”+
“11英寸”+
“0.5英寸”+
“1英寸”+
“1英寸”+
“0.5英寸”+
"";
警告[]警告;
字符串[]流;
字节[]渲染字节;
//提交报告
renderedBytes=localReport.Render(
报告类型,
deviceInfo,
输出mimeType,
输出编码,
输出文件名扩展名,
流出的溪流,
发出警告);
AddHeader(“内容处置”、“附件;文件名=数据”+“文件名扩展名”);
返回文件(renderdbytes,mimeType);
}
公共静态列表GetAllData()
{
var entities=新数据实体();
var x=来自entities.vwDataReport中的c
选择c;
返回x.ToList();
}

创建一个包含两个日期的ViewModel,即

public class ReportModel
{
   public DateTime StartDate { get; set; }
   public DateTime StartEnd { get; set; }
}
初始化并将其发送回Get方法,这将呈现一个日期选择屏幕,即

public ActionResult DetailsReport()
{
     var model = new ReportModel();
     model.StartDate = DateTime.Now;
     model.StartEnd = DateTime.Now;
     return View(model);
}
在视图中呈现控件以显示它们,即,如果使用jQuery UI,如下所示:

@model ReportModel

@using(Html.BeginForm()){
@Html.TextBoxFor(m => m.StartDate, String.Format("{0:dd/M/yy}", Model.StartDate),
  new { @class = "datepicker datepicker-init" })

@Html.TextBoxFor(m => m.StartEnd, String.Format("{0:dd/M/yy}", Model.StartEnd),
  new { @class = "datepicker datepicker-init" })
<input type="submit" value="submit" />
}

<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery-ui-1.10.3.js"></script>
<script type="text/javascript">
        $(".datepicker").datepicker({
            minDate: 0,
            dateFormat: 'dd/mm/y'
        });

</script>

例外情况是什么?从哪里获得?
[HttpPost]
public ActionResult DetailsReport(ReportModel model)
{
    ...
    var startDate = model.StartDate.ToString();
    var startEnd = model.StartEnd.ToString();
    ReportParameter param0 = new ReportParameter("dtStartDate", startDate);
    ReportParameter param1 = new ReportParameter("dtStartEnd", startEnd);
    ...
}