You must Sign In to post a response.
  • Category: .NET

    How to get values in Asp.net MVC

    Hi

    Asp.net MVC

    How to get Value from One method to another method present in same controller

    like session
    but session not working here

    i tried like this

    ViewData["OrderId"] = OrderId;
    ViewBag.OrderId = OrderId;
    TempData["OrderId"] = OrderId;
  • #770012
    Hi,

    Did you tried of using TempData, To pass some data from one action method to another while redirecting the user to another action method.
    Ex

    public ActionResult ControllerMethod1()
    {
    TempData.Add("OrderId", OrderId);
    return RedirectToAction("ControllerMethod2"); // Below action method will be called
    }

    public ActionResult ControllerMethod2()
    {
    return Content(TempData["OrderId"].ToString());
    }


    Hope this will help you.

    Regards,
    SonyShiva
    Never lose hope..You never know what tomorrow will bring

  • #770013
    Hi
    I am using your code also not working. when i postback all the values cleared.

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


  • Sign In to post your comments