开发者

Value not passing when redirecting from controller to another controller while passing data in MVC 2

开发者 https://www.devze.com 2023-02-04 03:27 出处:网络
Is it possible to pass data from one controller to another? When my second controller is called the int id is showing the WRONG value:

Is it possible to pass data from one controller to another? When my second controller is called the int id is showing the WRONG value:

I have one controller:

public ActionR开发者_运维技巧esult Index(int id)
{
  return RedirectToAction("New", "NewProducts", id);
}

NewProductsController:

public string New(int id)//    <--------id never has correct number when called
{

  return "value: " + id;

}


You need to use either a RouteValueDictionary or an anonymous type with an id property for the route values otherwise it will use the properties on the Int32 object id to fill the route values dictionary.

public ActionResult Index(int id)
{
  return RedirectToAction("New", "NewProducts", new { id = id } );
}


Hope it will work

public ActionResult Index(int id)
{
    return RedirectToAction("New?id=" + id, "NewProducts");
}

0

精彩评论

暂无评论...
验证码 换一张
取 消