私のテスト セットアップは、モデル コレクション内の各項目の画像をレンダリングする目的で単純なモデルを反復処理する foreach を含むビューで構成されています。ループ内には、コントローラーで FileContentResult メソッドを呼び出す 2 つの @Url.Action ヘルパーがありますが、1 つはビューからパラメーターを取得し、もう 1 つはハードコーディングされたパラメーター変数を持っていることを除いて同一です。
@foreach (var i in Model.FeaturedItems)
{
<img src="@Url.Action("GetFooImage", "Home", new {})" alt="@i.Name" />
<img src="@Url.Action("GetFoobarImage", "Home", new {i.ItemID, Entity="item", Size="m"})" alt="@i.Name" />
}
私のコントローラでは、2 つのメソッドは次のとおりです。
public FileContentResult GetFooImage() // variables hard coded in body
public FileContentResult GetFoobarImage(int id, string entity, string size)
GetFooImage() は画像を返します。FileContentResult GetFoobarImage() はしません。
ここに謎があります。GetFoobarImage にブレークポイントを設定しても、ヒットしません。GetFooImage が呼び出される理由がわかりませんが、GetFoobarImage は呼び出されません。