Asp.net mvc 4 尝试在视图中显示图像时,Asp.net MVC无法检索查询字符串

Asp.net mvc 4 尝试在视图中显示图像时,Asp.net MVC无法检索查询字符串,asp.net-mvc-4,query-string,Asp.net Mvc 4,Query String,这是我的目标页面设计,我在其中显示图像 这是我的源代码页,我在其中绑定我的linkbutton,如下所示 @Html.ActionLink(“QuestionTitle”、“Index”、“Display”,新的{QuestionID=item.QuestionID},null) 在浏览器中单击上述url时,我的目的地如下 http://localhost:1931/Display?QuestionID=1 这是我试图显示图像的代码 [HttpGet] public ActionResult

这是我的目标页面设计,我在其中显示图像

这是我的源代码页,我在其中绑定我的
linkbutton
,如下所示

@Html.ActionLink(“QuestionTitle”、“Index”、“Display”,新的{QuestionID=item.QuestionID},null)

在浏览器中单击上述url时,我的目的地如下

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");
    }

有人能告诉我如何在每一页上获取
查询字符串吗除了这一页之外,我能在每一页上获取查询字符串。

在您的目标页中,您应该使用

<img alt="" src="@Url.Action("GetPhoto", "Display", new {QuestionId=Model.Id})" height="50" width="50" class="photo" />

(例如,我假设您有一个具有Id属性的模型)

这与您在源页面中调用显示控制器的索引操作的方式相同

没有路由数据
@Url.Action(“GetPhoto”,“Display”)
生成链接
http://localhost:1931/Display/GetPhoto


使用路由数据(第三个参数),生成的链路是
http://localhost:1931/Display/GetPhoto?QuestionId=

为什么不为您的操作提供一个参数呢<代码>公共操作结果GetPhoto(字符串QuestionID)
仍然无法获取所需的ID