locked
passing data between different view with different controller to another view RRS feed

  • Question

  • User-1634604574 posted

    how can i pass textbox data from one view to different view in different controller

    Sunday, February 17, 2019 5:09 AM

All replies

  • User-2054057000 posted

    Use session variable which you set value in any controller like this:

    Session["Name"] = "JACK SPARROW";

    To get session value in controller:

    string myName = Session["Name"].ToString();

    And in the same way you can use the session in the view:

    @Session["Name"] = "JACK SPARROW";
    
    @Session["Name"].ToString();

    Now for Performing Redirections in Action Methods I would suggest you to use RedirectToAction method like this:

    return RedirectToAction("Customer","List");

    Regards

    Sunday, February 17, 2019 12:10 PM
  • User-1634604574 posted

    can i set session from the view?can you explain it by example?

    Sunday, February 17, 2019 12:50 PM
  • User1520731567 posted

    Hi zhyanadil.it@gmail.com,

    can i set session from the view?

    Yes,you can.

    You just assignments to Session are done inside @{..} block,for example:

    In view:

    @{ 
    Session["aaa"]="123456"; //set session
    } .... <h3>@Session["aaa"].ToString()</h3> //call session

    Best Regards.

    Yuki Tao

    Monday, February 18, 2019 7:07 AM