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.
パラメーターを null 可能にした後id
、対応するアクション メソッドが 2 回呼び出されていることがわかりました。コードを確認すると問題ないように見えますが、なぜこれが起こっているのかわかりません。
アクション メソッドのルートは次のとおりです。
_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" });
インクルードウィジェット機能。コードは以下のようなものです:
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
ルート パラメーターの名前を変更して、ビュー ページから参照をスクリプト化しようとしましたが、新しいパラメーター名に基づいて同じエラーが表示されます。この問題を解決するにはどうすればよいですか?