Reputation: 6477
I have a situation in my View where certain controls ie Checkbox or Textbox should only show if a certain value is selected in a dropdown list. The question is what is the recommended approach to handle this:
Use JQuery to show a control when the dropdown is populated.
Return to controller, for relevant action to at least redisplay the View, passing through the View Model with new data, thereby enabling Razor to display the conditional controls. The advantages with this approach that I can see is that the process is managed by controller and same language(Razor/C#) is used.
Many thanks.
Upvotes: 1
Views: 233
Reputation: 7765
Jquery or javascript is the best method here.
Using the controller to make view changes based on a select box change doesn't follow separation of concerns or the MVC pattern.
You might as well use WebForms if you're going to make a postback for such a simple thing
Upvotes: 2