开发者

POST not accepting int parameter

开发者 https://www.devze.com 2023-04-09 11:44 出处:网络
I have a problem with ASP.NET MVC3. I\'m trying to post some parameters to a JSONResult action. It works great when i use GET, but when i use POST, i get an error, because apparently when using POST,

I have a problem with ASP.NET MVC3.

I'm trying to post some parameters to a JSONResult action. It works great when i use GET, but when i use POST, i get an error, because apparently when using POST, it won't accept my integer parameters as such, and say that the parameters dictionary contains a null value for them.

Anyone run across this before? Thanks.

Edit: some code, as requested:

public JSONResult PostingHere(string username, int someotherparameter) {
    //Code   
}

Really, that's all that matters, because the exception is thrown then and there when POSTing because apparantly a null value gets passed to the someotherparameter parameter. When using GET, as said before, it works just dandy.

The intended use is to post with a NSURLRequest from an iPhone, but I've been debugging with a firefox extension called Poster and i get the same result. Full error:

The parameters dictionary contains a null entry for parameter 'someotherparameter' of non-nullable type 'System.Int16' for method 'System.Web.Mvc.JsonResult PostingHere(System.String, Int16)'

Edit 2: By request, I'll add an example of calling the action which results in the error:

<form action="http://fullurlhere.com/Controller/PostingHere" method="POST">
<input type="hidden" name="userid" value="astring" />
<input type="hidden" name="someotherparameter" value="100" />
<input type="submit" value="Brace for impact" />
</form>

Edit 3: The post data; never mind the discrepancy in variable names, these are the actual names of them.

POST not accepting int parameter

Edit 4: Adding to the mystery, the problem disappears when testing aga开发者_如何学编程inst a local server on my own computer, with the very same MVC Project the server is running. So the problem is likely within a server-side setting.

Solved: Turns out when i evalutated the request, that the server was redirecting me to https:// from the http://, causing me to lose my POSTed data. Thanks to everyone for being such good sports.


try

public JSONResult PostingHere(string username, int? someotherparameter) {
    //Code   
}


Solved: Turns out when i evalutated the request, that the server was redirecting me to https:// from the http://, causing me to lose my POSTed data. Thanks to everyone for being such good sports.

0

精彩评论

暂无评论...
验证码 换一张
取 消