@using (Html.BeginForm("AddPhysician", "Appointment", new { viewModel = Model }, FormMethod.Post))
{
where Model is a created class of type AppointmentPhysicianLinkViewModel that has all the proper values and if I stop on this line, the value Model is correctly populated. Then when the submit button is pressed the code is in my controller
doesn't make sense. a url string maxs at 2k, so query parameters are smaller. to pass the model on the query string, you would need to serialize to a string, then hope its small enough.
if you want a model passed back via post, then just serialize to a string and place it in a hidden fields.
Bob N
Member
88 Points
72 Posts
Parameters in Html.BeginForm
Nov 09, 2012 04:05 PM|LINK
Here is my code for my form
@using (Html.BeginForm("AddPhysician", "Appointment", new { viewModel = Model }, FormMethod.Post)) {where Model is a created class of type AppointmentPhysicianLinkViewModel that has all the proper values and if I stop on this line, the value Model is correctly populated. Then when the submit button is pressed the code is in my controller
[IHIAuthorize, HttpPost] public ActionResult AddPhysician(User user, AppointmentPhysicianLinkViewModel viewModel) { PatientPhysician pp = new PatientPhysician(_dataservice); pp.PatientID = (int)user.Patient.PatientID; pp.PhysicianName = viewModel.Name; pp.PhysicianEmail = viewModel.Email != null ? viewModel.Email : string.Empty;Can someone please tell me what I'm doing wrong?
Thanks
Bob
BrockAllen
All-Star
27574 Points
4912 Posts
MVP
Re: Parameters in Html.BeginForm
Nov 09, 2012 04:21 PM|LINK
You can't put a full object into your route params in an ActionLink or BeginForm -- it only supports/accepts simple values.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
Bob N
Member
88 Points
72 Posts
Re: Parameters in Html.BeginForm
Nov 09, 2012 04:56 PM|LINK
Thanks
rcalderoni
Member
2 Points
5 Posts
Re: Parameters in Html.BeginForm
Nov 09, 2012 05:39 PM|LINK
Now that would be a great feature, MVC 5?
bruce (sqlwo...
All-Star
36894 Points
5452 Posts
Re: Parameters in Html.BeginForm
Nov 09, 2012 07:10 PM|LINK
doesn't make sense. a url string maxs at 2k, so query parameters are smaller. to pass the model on the query string, you would need to serialize to a string, then hope its small enough.
if you want a model passed back via post, then just serialize to a string and place it in a hidden fields.