繁体   English   中英

参数字典包含用于方法的非空类型'System.Int32'的参数'foo'的空条目

[英]The parameters dictionary contains a null entry for parameter 'foo' of non-nullable type 'System.Int32' for method

从我在其他文章中看到的错误来看,该错误是因为方法签名中给定的参数与发布的输入名称不匹配。 或以某种方式甚至不发送值。

首先,此页面是登录到Facebook的测试页面。 它检索用户的uid和访问令牌,然后将其发送到服务器以存储在会话中并重定向到另一个页面。 所有的javascript都是从C#FB sdk中获得的,服务器端是非常基本的。

我感到困惑的真正问题是,如果我以自己的帐户在FB上登录,但测试用户而不是API生成的临时测试用户帐户的朋友,则它可以正确运行,但在弹出窗口要求用户授予应用权限。 我在提交表单数据之前就已经对其进行了查看,并且该表单数据具有隐藏的输入,以及与服务器上我的参数相对应的名称和值。

知道为什么它不通过测试用户通过帖子发送foo变量吗?

编辑:这是对我的帐户正确运行的javascript,无法为测试用户发送uid。 我重命名了一些查询字符串参数,但是

var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;

// Do a post to the server to finish the logon
// This is a form post since we don't want to use AJAX
var form = document.createElement("form");
form.setAttribute("method", 'post');
form.setAttribute("action", 'BAR>');

var tField = document.createElement("input");
tField.setAttribute("type", "hidden");
tField.setAttribute("name", 'RAHR');
tField.setAttribute("value", accessToken);
form.appendChild(tField);

var uField = document.createElement("input");
uField.setAttribute("type", "hidden");
uField.setAttribute("name", 'foo');
uField.setAttribute("value", uid);
form.appendChild(uField);

document.body.appendChild(form);
form.submit();

//Server side
public ActionResult BAR(string RAHR, int foo)

原来,输入的值太大。 导致int参数溢出,而不是给出一个奇怪的值,MVC将其清零了。

将您的方法从-> public ActionResult BAR(字符串RAHR,int foo)替换为-> public ActionResult BAR(字符串RAHR,int?foo)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM