たくさんの質問とインターネットデータを確認した後、MVC3アプリケーションからURLパラメータを正しく取得するという私の問題を解決しました。コーディングに問題はなく、ルーティングに問題があったということです(私はルーティングがあまり得意ではありません...)。これが現在の問題です。
http://localhost:51561/Report/Details/1
これは、私のアプリケーションがレポートの詳細を表示する方法です。これは良いことです。しかし、このようにすると、URLパラメータから値を取得できなくなります。
Request.QueryString["id"]
しかし、手動でURLを入力すると、機能しhttp://localhost:51561/Report/Details?id=1
ます...最初のURLタイプが好きですが、そこからパラメーターを取得する方法がわかりません...
助けてください...
アップデート:
私のコントローラーのアクション:
public ViewResult Details(int id)
{
Report report = db.Reports.Find(id);
ViewBag.TestID = Request.QueryString["id"].ToString();
return View(report);
}
public ActionResult Show(int id)
{
Report report = db.Reports.Find(id);
var imageData = report.Image;
return (File(imageData, "image/jpg"));
}
私の見解:
<div class="display-label">Picture</div>
<div class="display-field">
<img alt="image" src="<%=Url.Action("Show", "Report", new { id = ViewBag.TestID })%>" width="200px" />
</div>