SamJolly
SamJolly

Reputation: 6477

Best method to handle dynamic View logic for showing controls, JQuery or return to controller for View refresh?

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:

  1. Use JQuery to show a control when the dropdown is populated.

  2. 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

Answers (1)

Eonasdan
Eonasdan

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

Related Questions