model view controller - access to request querystring in mvc -
i have actionlink in view:
@html.actionlink("go", "showdetails", "shownews", new { id = 2 },null);
and in routeconfig:
routes.maproute( name:"newmap", url: "{controller}/{action}/{id}", defaults: new { controller = "shownews", action = "showdetails", id = urlparameter.optional } );
when click on actionlink , request query string cod in controller
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); }
but request return me return 1 (i send 2 actionlink) when go address :
localhost/shownews/showdetails?id=2
request.querystring pars 2 value(this true) problem?
Comments
Post a Comment