Model view controller 在mvc中访问请求查询字符串
我认为有一个actionLink:Model view controller 在mvc中访问请求查询字符串,model-view-controller,Model View Controller,我认为有一个actionLink: @Html.ActionLink("go", "ShowDetails", "ShowNews", new { id = 2 },null); 在我的RouteConfig中: routes.MapRoute( name:"newMap", url: "{controller}/{action}/{id}", defaults: new { controller = "shownews"
@Html.ActionLink("go", "ShowDetails", "ShowNews", new { id = 2 },null);
在我的RouteConfig中:
routes.MapRoute(
name:"newMap",
url: "{controller}/{action}/{id}",
defaults: new { controller = "shownews", action = "showdetails", id = UrlParameter.Optional }
);
在我的控制器中单击此actionLink并通过此cod请求查询字符串时
public ActionResult ShowDetails()
{
int id;
if (!int.TryParse(Request.QueryString["id"], out id))
{
id = 1;
}
var data = new DatabaseContext();
var news = data.newsInfo.Where(x => x.ID == id).FirstOrDefault();
return View(news);
}
但是这个请求返回给我总是返回1我通过actionLink发送2
但当我去地址:
localhost/ShowNews/ShowDetails?id=2
request.querystring pars为2值这是真的
问题是什么?这是什么语言?这在逻辑上意味着什么:Wherex=>x.ID==ID?c-这部分代码'Wherex=>x.ID==ID'不重要,我想访问query stringmaybe Request.QueryStringid?这种语法在VB.Net中工作,在c中是Request.QueryString[ID]您在ShowDetails中记录了Request.QueryString[ID]的值吗?