2
votes

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?

3
Ok, I solved it out. The problem was when I first request the page. server is invoking Index action. But because of there is not any form posted to server I'm getting this error. Solve is: add new parameterless Index action only returns view. and add [Httppost] attribute to existing one. - beratuslu

3 Answers

1
votes

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)

0
votes

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?

0
votes

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