7

what I'm used to do up until now, when there's need to dynamically set html elements style, (using web forms), I was setting hidden input(s), passing data from code behind and using jQuery to manipulate some elements.

so c# requests > passes data to html hidden field > jQuery reads and execute.

 chosenHtmlElm.css({ 
        'background-image': 'url(images/RegF.png)' },
        { 'visibility': 'visible' 
 });

is there a simple & elegant solution or should I stick to my old-school technique ?

  web page with content items 

[type1]    [default]    [type2]    [default]    []

[]    []    []    []    []

those could lead to an article / category within the website ...

so type1 has a left corner image, type2 has a right corner image default has non

I think of a logic to give each an id of category Content item, and I could then construct some logic to manage it change order, change the icon...

dchayka
  • 1,291
  • 12
  • 20
RonenMaziner
  • 119
  • 3
  • Is this targeting forms only or other elements on the page as well? – dchayka Mar 16 '16 at 14:41
  • 2
    Your technique is strangely indirect; there is no need to involve hidden input fields. Why not have your jQuery request and receive its data directly? – Daniel Beck Mar 16 '16 at 14:55
  • @DanielBeck pageload event is saving one round trip I guess .. that's my old version of technique / off course ajax post is heavily used after first page req – RonenMaziner Mar 23 '16 at 16:56
  • You can try to use binding libraries to update the element attributes... http://rivetsjs.com/docs/guide/#binders – damitj07 Mar 29 '16 at 10:39

1 Answers1

0

I think of MVC UI in three parts

  1. There's functionality via the routing; different UI pages for edit, list, etc
  2. There's data, provided via the model: some UI state things can be provided through the model, and update the style via the model.
  3. There's the UI logic, that needs it's own source for responding to user needs.

The last item includes AJAX updates: State selection (rules fired based on updated UI dropdown selection, for example), GeoIP, and changes for the CSS you might require. I use a separate controller for the UI related AJAX for a particular route. You could use the same controller, but I like to compartmentalize the logic

Robert Achmann
  • 1,986
  • 3
  • 40
  • 66