简体   繁体   中英

Id is always null in [HttpGet] action

I am redirecting to another page with Id as a parameter. I passed Id successfully by using RedirectToAction but the controller action method is not accepting id and giving it null always even when there is Id in the url

Code to Redirect to that page

   return RedirectToAction("myaction", new System.Web.Routing.RouteValueDictionary(
                    new { controller = "mycontroller", action = "myaction", Id = 1 }));

Url looks like this

  http://localhost:1234/mycontroller/myaction/1

The Action looks llike this

  [HttpGet]
  public ActionResult myaction(int? Id)
  {
      // ID is null here 
  }

Try this once

return RedirectToAction("myaction", "mycontroller", new {Id = 1} ); 

or

return RedirectToAction("myaction", "mycontroller", 
       new System.Web.Routing.RouteValueDictionary( new { Id = 1 }));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM