tags:

views:

37

answers:

3

I have action method like that:

public ActionResult Index(HttpPostedFileBase image, int variable)

and form element like that:

variable 1:<input type="text" name="variable" value="1234" />

when I start debugging I am getting following exception:

The parameters dictionary contains a null entry for parameter 'variable' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Index(System.Web.HttpPostedFileBase, Int32)' in 'Stream.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

what is wrong with this?

+1  A: 

Try this:

public ActionResult Index(HttpPostedFileBase image, int? variable)

The question mark ( ? ) indicates that variable is a nullable variable and then it can be assigned the null value.

To know more about nullable types, read this on MSDN: Nullable Types (C# Programming Guide)

Leniel Macaferi
+1, but you should tell this poor person what a nullable int is so he doesn't sit there, scrathing his head, wondering what the question mark is for... I was a .Net developer for years before I ran across them.
David Stratton
David, I was just doing that while you wrote your comment. :)
Leniel Macaferi
It's not null..
berotomanya
The thing is that the error you're getting is informing just that it's null: The parameters dictionary contains a null entry for parameter 'variable' of non-nullable type 'System.Int32'.
Leniel Macaferi
I know what nullable types are? poor person.
berotomanya
Are you shure, Do you have enough knowledge to answer this question?
berotomanya
A: 

Hey,

Try:

<input type="text" id="variable" name="variable" value="1234" />

Give an ID and see if you get the same issue... also, I know you probably know this, but to verify, you did put it within the form being posted, correct?

Brian
A: 

Ensure that your <input> is in a <form> tag, and that the form is the one whose action is being executed.

p.campbell