パラメータとして取り、そのエンティティをロードするActionResult呼び出しを介してレンダリングされるページがあります。EntityIndexint id
このビューでは、ユーザーはドロップダウンから他の関連エンティティを選択でき、ドロップダウンから選択した ID をEntityIndex新しいID.
ドロップダウンで jQuery 変更イベントを使用して、ページをナビゲートして再読み込みしています。
$("#RelatedEntity").change(function () {
window.location = '@Url.Action("EntityIndex", new {id = ""})' + '/' + $(this).val();
});
これがアクションです
public ActionResult EntityIndex(int id) {
... gets entity by id here ...
return View(model);
}
ヒットするとアクションは正常に機能しますが、上記の jQuery 行はエラーで失敗します。
http://localhost:1798/Entity/EntityIndex/@Url.Action("EntityIndex", new {id = ""})/539
何らかの理由で、をwindow.location起動する@Url.Actionと、アクションがナビゲートするアクションではなく文字列として扱われます... がUrl.Action正しく動作しない原因は何ですか?