我的MVC C#应用程序出错了。虽然我没有在开发环境中遇到以下错误,但是甚至功能都没有破坏,但是当在IIS服务器上部署它时,我通过elmah通过电子邮件获得此错误,并在数据库中输入相应的条目
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult DetailSmallForeignWidget(System.String, Int32, System.String, System.Nullable`1[System.Int32], System.Nullable`1[System.DateTime], System.Nullable`1[System.Int32], System.String, System.String)' in 'BAR.Web.Controllers.ForeignRestaurantWidgetController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
使id
参数可以为空后,我知道相应的动作方法被调用了两次。查看代码看起来很好,但不知道为什么会发生这种情况。
动作方法的路线如下:
_routes.MapRoute(null, "widget/DetailWidget/{name}/{id}/{langID}/",
new { controller = "Widget", action = "DetailWidget" },
new[] { "BAR.Web.Controllers" });
功能签名如下:
public override ActionResult DetailWidget(
string name,
int id,
string refCode,
int? partySize,
DateTime? when,
int? sittingTimeId,
string time,
string langID)
<script type="text/javascript" src="http://localhost/widget/IncludeWidget/Street/205/iframe/ja-JP" ></script>
对应路线
_routes.MapRoute(null, "widget/IncludeWidget/{name}/{id}/{mode}/{langID}/",
new { controller = "Widget",
action = "IncludeWidget" },
new[] { "BAR.Web.Controllers" });
Inside Includewidget func。代码如下所示:
ContentResult content = new ContentResult();
string url = Url.ToAbsoluteUrl(string.Format("widget/DetailWidget/{0}/{1}/{2}", name, id.Value, langID), true);
content.Content = @"document.write('<iframe src=""" + url + @""" width=""300"" height=""430"" style=""border: none;"" frameborder=""0""></iframe>')";
content.ContentType = "text/javascript";
return content
我尝试重命名路由参数并尝试从视图页面编写脚本引用,但它仍然显示基于新参数名称的相同错误。我该如何解决这个问题?