Alex
Alex

Reputation: 827

Passing variables between action methods and show on view?

I have a controller like below

           [HttpPost]
            public JsonResult Index(string number)
            {
             ....
                ServiceReference1.WebsiteInterfaceSoapClient APITest = new ServiceReference1.WebsiteInterfaceSoapClient();
                List<ServiceReference1.Student> ListStudents = APITest .CheckIDStudent("xxxxxxxxxxxxx", number).ToList();
             ....

              }

and I have a method like this

    [HttpPost]
    public async Task<ActionResult> ValidateS(StudentsDetails userDetails, string marksPoint)
    { 
            ....
    }

How can I pass all the data on ListStudents like (ListStudents[0].ID, ListStudents[0].Name ...) into ValidateS method and show them on View?

Upvotes: 0

Views: 57

Answers (1)

Amir Jelo
Amir Jelo

Reputation: 347

You can't do the redirect function for [HttpPost] action. So you have to change your ValidateS action method to [HttpGet]. and use TempData feature.

[HttpPost]
public JsonResult Index(string number)
{
    ServiceReference1.WebsiteInterfaceSoapClient APITest = new ServiceReference1.WebsiteInterfaceSoapClient();
    List<ServiceReference1.Student> ListStudents = APITest .CheckIDStudent("xxxxxxxxxxxxx", number).ToList();
    TempData["studentList"] = ListStudents;
}

[HttpGet]
public async Task<ActionResult> ValidateS(StudentsDetails userDetails, string marksPoint)
{ 
    List<ServiceReference1.Student> studentList = TempData["studentList"] as List<ServiceReference1.Student>;
}

Upvotes: 2

Related Questions