-
Jul 21st, 2017, 09:33 AM
#1
Thread Starter
Fanatic Member
The parameters dictionary contains a null entry for parameter 'Width' of non-nullable
Controller: Report
Action: Index
Exception: The parameters dictionary contains a null entry for parameter 'Width' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(System.String, System.String, Int32, Int32)' in '*******.Areas.Reports2.ReportController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
I am receiving this error trying to set up an SSRS report in MVC a basic report access in its folder by URL. Can someone help me out /
here is the code
ReportsAreaRegistration
Code:
using System.Web.Mvc;
namespace *******.Areas.Reports2
{
public class ReportsAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "Reports2";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Reports2_default",
"Reports2/{controller}/{action}/{id}",
new { controller = "Default", action = "Index", id = UrlParameter.Optional, Width = UrlParameter.Optional, Height = UrlParameter.Optional }
);
}
}
}
Report view
Code:
@model.******.Areas.Reports2.Models.ReportInfo2
<H1>
@Model.ReportDescription
</H1>
<iframe id="frmReport" src="@Model.ReportURL" frameborder="0" style="@String.Format("width:{1}%; height: {1}px;", Model.Width, Model.Height)" scrolling="no">
</iframe>
ReportController
Code:
namespace *******.Areas.Reports2
{
//[Authorize]
public class ReportController : Controller
{
//GET: Report
//public ActionResult Index()
//{
// return View();
//}
public ActionResult Index( string ReportName,string ReportDescription, int Width, int Height)
{
var rptInfo = new ReportInfo
{
ReportName = ReportName,
ReportDescription = ReportDescription,
ReportURL = String.Format("http://************/rsreports/Pages/Report.aspx?ReportName={0}&Height={1}&ManagerList={2}", ReportName, Height),
Width = Width,
Height = Height
};
rptInfo.number3 = rptInfo.number1 + rptInfo.number2;
//return View(model);
return View(rptInfo);
}
}
}
HomeController
[CODE]
namespace *******.Areas.Reports2.Controllers
{
public class HomeController : Controller
{
// GET: Reports2/Home
public ActionResult Index()
{
return View();
}
}
}
Home View
Code:
@{
ViewBag.Title = "Index";
}
<h2>Reports List</h2>
<a id="ReportUrl_Performance" href="@Url.Action("ReportTemplate", "Report", new { ReportName = "ManagerList", ReportDescription = " Report", Width = 100, Height = 650 })">
Y Based Report
</a>
-
Jul 21st, 2017, 11:03 AM
#2
Re: The parameters dictionary contains a null entry for parameter 'Width' of non-null
String.Format("width:{1}%; height: {1}px;", Model.Width, Model.Height) -- you passed in two parameters Model.Width and Model.Height... but then only used one (twice as it happens) ... So String.Format it throwing an exception because Model.Width wasn't used...
So... if you really do want height to be used for both values, you'll need to remove Model.Width and change the {1} to {0} ... OR, if you did mean to use both:
String.Format("width:{0}%; height: {1}px;", Model.Width, Model.Height)
-tg
-
Jul 21st, 2017, 11:04 AM
#3
Thread Starter
Fanatic Member
Re: The parameters dictionary contains a null entry for parameter 'Width' of non-null
What stumps me is this is generic code from an example another developer plunked down that he said this should work and now doesn't when I am looking at it and online this example exists and it is said to be working...very frustrating.
-
Jul 21st, 2017, 11:08 AM
#4
Thread Starter
Fanatic Member
Re: The parameters dictionary contains a null entry for parameter 'Width' of non-null
So in this statement it uses it once here...
Code:
ReportURL = String.Format("http://************/rsreports/Pages/Report.aspx?ReportName={0}&Height={1}&ManagerList={2}", ReportName, Height),
Width = Width,
Height = Height
....
-
Jul 21st, 2017, 11:10 AM
#5
Thread Starter
Fanatic Member
Re: The parameters dictionary contains a null entry for parameter 'Width' of non-null
How would the solution look to use both ideally ?
I have changed the code to reflect this:
Code:
[HttpGet]
public ActionResult Index( string ReportName,string ReportDescription, int Width , int Height )
{
var rptInfo = new ReportInfo
{
ReportName = ReportName,
ReportDescription = ReportDescription,
ReportURL = String.Format("http://ifgsqldev.infinexgroup.com/rsreports/Pages/Report.aspx?ReportName={0}&Height={1}", ReportName, Width, Height),
Width = Width,
Height = Height
};
and now changed the code to say this
Code:
@model.******.Areas.Reports2.Models.ReportInfo2
@using Kendo.Mvc.UI
<H1>
@Model.ReportDescription
</H1>
<iframe id="frmReport" src="@Model.ReportURL" frameborder="0" style="@String.Format("width:{0}%; height: {1}px;", Model.Width, Model.Height)" scrolling="no">
</iframe>
It still gives me the same error as in the heading of the topic.
The parameters dictionary contains a null entry for parameter 'Width' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(System.String, System.String, Int32, Int32)' in 'Infinet.Areas.Reports2.ReportController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
Last edited by Christopher_Arm; Jul 21st, 2017 at 11:17 AM.
-
Jul 21st, 2017, 12:02 PM
#6
Re: The parameters dictionary contains a null entry for parameter 'Width' of non-null
Originally Posted by Christopher_Arm
So in this statement it uses it once here...
Code:
ReportURL = String.Format("http://************/rsreports/Pages/Report.aspx?ReportName={0}&Height={1}&ManagerList={2}", ReportName, Height),
Width = Width,
Height = Height
....
Now, in THAT one, you have THREE parameter place holders, but only supplied two... you need to add a third... my guess would be what ever the ManagerList is supposed to be... what's with the comma and the extra stuff there too? That should be throwing a syntax error. That maybe what you're seeing... (never mind, ignore that, I see you're calling a constructor and passing them in, so that's good)
Originally Posted by Christopher_Arm
How would the solution look to use both ideally ?
I have changed the code to reflect this:
Code:
[HttpGet]
public ActionResult Index( string ReportName,string ReportDescription, int Width , int Height )
{
var rptInfo = new ReportInfo
{
ReportName = ReportName,
ReportDescription = ReportDescription,
ReportURL = String.Format("http://ifgsqldev.infinexgroup.com/rsreports/Pages/Report.aspx?ReportName={0}&Height={1}", ReportName, Width, Height),
Width = Width,
Height = Height
};
and now changed the code to say this
Code:
@model.******.Areas.Reports2.Models.ReportInfo2
@using Kendo.Mvc.UI
<H1>
@Model.ReportDescription
</H1>
<iframe id="frmReport" src="@Model.ReportURL" frameborder="0" style="@String.Format("width:{0}%; height: {1}px;", Model.Width, Model.Height)" scrolling="no">
</iframe>
It still gives me the same error as in the heading of the topic.
The parameters dictionary contains a null entry for parameter 'Width' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(System.String, System.String, Int32, Int32)' in 'Infinet.Areas.Reports2.ReportController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
Ok, now hold on... it feels like you're slinging code around without understanding how string.format works...
Code:
ReportURL = String.Format("http://ifgsqldev.infinexgroup.com/rsreports/Pages/Report.aspx?ReportName={0}&Height={1}", ReportName, Width, Height),
Width = Width,
Height = Height
That still isn't right... now you have three parameters but only two placeholders.... if you want three things in there, you need three placeholders... {0} being the first, {1} being the second and {1} being the third.
It should be this:
Code:
ReportURL = String.Format("http://ifgsqldev.infinexgroup.com/rsreports/Pages/Report.aspx?ReportName={0}&Width={1}&Height={2}", ReportName, Width, Height),
I'm no expert in MVC but I think this is the problem:
Code:
<a id="ReportUrl_Performance" href="@Url.Action("ReportTemplate", "Report", new { ReportName = "ManagerList", ReportDescription = " Report", Width = 100, Height = 650 })">
Y Based Report
</a>
You're invoking the action using String, String, Object.... but the signature is looking for String, String, Int32, Int32... so you're getting an object where it is expecting the Width value to be passed in.
What happens when you change it to this:
Code:
<a id="ReportUrl_Performance" href="@Url.Action("ManagerList", "Report", Width = 100, Height = 650)">
Y Based Report
</a>
-tg
-
Jul 21st, 2017, 12:32 PM
#7
Thread Starter
Fanatic Member
Re: The parameters dictionary contains a null entry for parameter 'Width' of non-null
Ok. I have changed the code to reflect three parameters as you mentioned.
Code:
[HttpGet]
public ActionResult Index( string ReportName,string ReportDescription, int Width , int Height )
{
var rptInfo = new ReportInfo
{
ReportName = ReportName,
ReportDescription = ReportDescription,
ReportURL = String.Format("http://@@@sqldev.infinexgroup.com/rsreports/Pages/Report.aspx?ReportName={0}&Width={1}&Height={2}", ReportName, Width, Height),
Width = Width,
Height = Height
};
rptInfo.number3 = rptInfo.number1 + rptInfo.number2;
//return View(model);
return View(rptInfo);
}
and I have made changes to the view as a you stated below. Still getting the same reported error for the width parameter.
-
Jul 21st, 2017, 12:36 PM
#8
Thread Starter
Fanatic Member
Re: The parameters dictionary contains a null entry for parameter 'Width' of non-null
What I can see is for this view thee model conditions all have red lines under them..
Code:
@model.@@@@.Areas.Reports2.Models.ReportInfo2
<H1>
@Model.ReportDescription
</H1>
<iframe id="frmReport" src="@Model.ReportURL" frameborder="0" style="@String.Format("width:{0}%; height: {1}px;", Model.Width, Model.Height)" scrolling="no">
</iframe>
-
Jul 21st, 2017, 12:37 PM
#9
Thread Starter
Fanatic Member
Re: The parameters dictionary contains a null entry for parameter 'Width' of non-null
Yet when I go to the definition of the model itself it seems fine.
Code:
namespace @@@@.Areas.Reports2.Models
{
public class ReportInfo2
{
public int ReportId { get; set; }
public string ReportName { get; set; }
public string ReportDescription { get; set; }
public string ReportURL { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public string ReportSummary { get; set; }
public int number1 { get; set; }
public int number2 { get; set; }
public int number3 { get; set; }
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|