這是我的目標頁面的設計我在哪裏顯示圖像Asp.net MVC不能試圖在一個視圖中顯示的圖像時,檢索查詢字符串
<img alt="" src="@Url.Action("GetPhoto", "Display")" height="50" width="50" class="photo" />
這是我結合我的源頁面我linkbutton
如下
@Html.ActionLink("QuestionTitle", "Index", "Display", new { QuestionID = item.QuestionID }, null)
我,當我進行點擊瀏覽器上輸入的網址如下
目的地http://localhost:1931/Display?QuestionID=1
這是我的代碼,我想顯示圖像
[HttpGet]
public ActionResult GetPhoto()
{
// int quesID = Convert.ToInt16(Request.QueryString["QuestionID"].ToString()); this didn't worked so by having a look at quick watch I write the below
int quesID = Convert.ToInt16(Request.UrlReferrer.Query.Substring(12, 1));
byte[] photo = null;
var usrname = (from a in db.tblQuestions
where a.QuestionID == quesID
select new { a.UserName });
var v = db.tblUsers.Where(p => p.UserName == usrname.FirstOrDefault().UserName).Select(img => img.Photo).FirstOrDefault();
photo = v;
return File(photo, "image/jpeg");
}
有人能告訴我如何讓每一個網頁,我能得到查詢字符串,除了此頁面上的querystring
。
你爲什麼不給一個參數給你的動作? '公衆的ActionResult GetPhoto(字符串QuestionID)' – nemesv 2013-02-11 12:15:07
仍然沒有得到所需的ID – Dotnet 2013-02-11 12:17:22