【发布时间】:2012-12-28 22:02:49
【问题描述】:
我不确定这里发生了什么。
我有一个在我拥有的 jquery 脚本中调用的操作方法...
ondblClickRow: function (id) {
debugger;
var dummyURL ='@Url.Action("EditEncounter", "EditEncounter", new { encounterId = 0, popId = (int)TempData["POPULATIONID"] })';
var path = dummyURL.replace("-2", id);
document.location.href = path;
//new { encounterId = temp.EncounterId, popId = (int)TempData["POPULATIONID"] }'
}
由于某种原因,当我尝试使用 chrome 通过此路由导航到此页面时,我收到此异常:
The parameters dictionary contains a null entry for parameter 'popId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult EditEncounter(Int32, Int32)' in 'FocusedReadMissionsRedux.Controllers.EditEncounterController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
但在 IE 中,我调用了 action 方法,然后毫无意外地导航到了相应的页面。我一定是错过了什么?
更新 我注意到我收到了这个查询字符串...
encounterId=2245&popId=2
请注意“&”和“amp;”。我认为我的路线设置不正确。我会尝试几件事,让各位绅士知道会发生什么。
确认
这是我在 Internet Explorer 中的路线
encounterId=2245&popId=2
而且它有效。我只需要弄清楚为什么这个特定请求会发生这种情况。
更新
当我尝试调试我的程序时,Visual Studio 没有更新生成的 cshtml 文件。有没有人遇到过这种情况以及如何解决?
【问题讨论】:
-
您在 Chrome 开发者工具栏的
Network标签中看到了什么?请求的网址是什么?它是正确的吗?此外,当您检查页面的 HTML 时,标记中dummyURL的值是什么。最后一个问题:dummyURL.replace("-2", id)行是什么?您是否在方法中记录了这个id变量的值?此外,您似乎在那里使用 TempData,因为您知道如果从中读取的中间请求已经发出,它可能会被驱逐。例如,这可能是一个 AJAX 请求。 -
我确保 tempdata 字段已水合。那条线是为了在触发某个事件后获得准确的导航路线。我将使用 chrome 检查 html 流量。
标签: internet-explorer google-chrome asp.net-mvc-4 asp.net-mvc-routing