The parameters dictionary contains a null entry for parameter 'Width' of non-nullable-VBForums
Results 1 to 9 of 9

Thread: The parameters dictionary contains a null entry for parameter 'Width' of non-nullable

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    783

    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>

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    30,844

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    783

    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.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    783

    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
    ....

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    783

    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.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    30,844

    Re: The parameters dictionary contains a null entry for parameter 'Width' of non-null

    Quote Originally Posted by Christopher_Arm View Post
    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)

    Quote Originally Posted by Christopher_Arm View Post
    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    783

    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.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    783

    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>

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    783

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.