Yes you can pass the model that you have shown using
return RedirectToAction("GetStudent", "Student", student1 );
assuming student1
is an instance of Student
which will generate the following url (assuming your using the default routes and the value of student1
are ID=4
and Name="Amit"
)
.../Student/GetStudent/4?Name=Amit
Internally the RedirectToAction()
method builds a RouteValueDictionary
by using the .ToString()
value of each property in the model. However, binding will only work if all the properties in the model are simple properties and it fails if any properties are complex objects or collections because the method does not use recursion. If for example, Student
contained a property List<string> Subjects
, then that property would result in a query string value of
....&Subjects=System.Collections.Generic.List'1[System.String]
and binding would fail and that property would be null