When do this, Problem Solved.
RDLC Report Error System.NullReferenceException on asp.net core
jewel
1,186
Reputation points
I am stuck with a Great problem. When I am moving from one controller to another controller in my RDLC report and going to view the report the parameter error is coming. That is, after running the program, only one controller report is visible. If i look at the report of another controller, the error is coming.
After searching a lot, I can't find a solution to this problem anywhere. It would be great if the experts could help.
I am using Asp .NET Core 8.0.
and For Rdlc Report Add Windows Forms App> .Net8.0
//This is TestController Code
using AspNetCore.Reporting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Rdlc1.Data;
using Rdlc1.Models;
namespace Rdlc1.Controllers
{
public class TestController : Controller
{
private ApplactionDbContext _context;
private readonly UserManager<Appplactionuser> _userManager;
private readonly IWebHostEnvironment _webHostEnvironment;
public TestController(ApplactionDbContext context, UserManager<Appplactionuser> userManager, IWebHostEnvironment webHostEnvironment)
{
_context = context;
_userManager = userManager;
this._webHostEnvironment = webHostEnvironment;
}
public IActionResult Testprint()
{
int ext = (int)(DateTime.Now.Ticks >> 10);
String path = _webHostEnvironment.WebRootPath + @"\Reports\Report1.rdlc";
Dictionary<String, string> parmeter = new Dictionary<String, string>();
parmeter.Add("prm", "jewel");
var Data = _context.tbl_Companies.ToList();
LocalReport localreport = new LocalReport(path);
localreport.AddDataSource("DataSet1", Data);
var report = localreport.Execute(RenderType.Pdf, ext, parmeter, "");
return File(report.MainStream, "application/pdf");
}
}
}
//This is HomeController Code
using System.Diagnostics;
using AspNetCore.Reporting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Rdlc1.Data;
using Rdlc1.Models;
namespace Rdlc1.Controllers
{
public class HomeController : Controller
{
private ApplactionDbContext _context;
private readonly UserManager<Appplactionuser> _userManager;
private readonly IWebHostEnvironment _webHostEnvironment;
public HomeController(ApplactionDbContext context, UserManager<Appplactionuser> userManager, IWebHostEnvironment webHostEnvironment)
{
_context = context;
_userManager = userManager;
this._webHostEnvironment = webHostEnvironment;
}
public IActionResult Testprint()
{
int ext = (int)(DateTime.Now.Ticks >> 10);
String path = _webHostEnvironment.WebRootPath + @"\Reports\Report2.rdlc";
Dictionary<String, string> parmeter = new Dictionary<String, string>();
parmeter.Add("nws", "jewel");
var Data = _context.tbl_Companies.ToList();
LocalReport localreport = new LocalReport(path);
localreport.AddDataSource("DataSet1", Data);
var report = localreport.Execute(RenderType.Pdf, ext, parmeter, "");
return File(report.MainStream, "application/pdf");
}
}
}
Developer technologies ASP.NET ASP.NET Core
4,815 questions