Reputation: 15
I'm new to ASP MVC, and I'm not sure if this is the best solution. I want to display one of two different forms to the user based on what they select from a drop-down. If I was doing this as a regular site, I'd use hidden divs, but I'm not sure if that's the best practice for MVC. Which approach should I use?
Upvotes: 0
Views: 394
Reputation: 1038890
It's pretty clear that you need to use javascript in order to achieve this goal. The reason for this that only with javascript's onchange
event on the corresponding select
element you can plug some custom logic like showing/hiding forms and stuff. So you can have the 2 forms in separate divs and simply toggle their visibility depending on what gets selected in the dropdown. You may include the 2 forms in separate partials and then plug the necessary javascript to toggle their visibility. In general you could use a single form and toggle the visibility of different input fields depending on the user selection. Obviously on the server, when this form gets submitted, you might need to plug the same logic to decide which fields to process because event hidden, the values of the corresponding input fields will be sent to the server.
Upvotes: 1