✅ Is it a good idea to store CSS class as a property in my C# model?
Example
Then I store like
"Online","green-circle"
"Offline", "red-circle"
Or should I check the status and then add the css in my js code itself?
9 Replies
I ask this again because I would like more opinions
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Hi @TeBeCo
I just didn't like code duplication on back end and front end. Code duplication? How? Otherwise I again then have to check in .js I had need to maintain a list of Status in FE and BE and keep them in sync I could avoid this check if I just store it in the back end. and then I just do
I just didn't like code duplication on back end and front end. Code duplication? How? Otherwise I again then have to check in .js I had need to maintain a list of Status in FE and BE and keep them in sync I could avoid this check if I just store it in the back end. and then I just do
I guess it's really a personal preference and there's nothing wrong with what you're doing, but IMO the back-end should not be responsible for any styling or other CSS/HTML related stuff, that's the front-ends job. The back-end provides data and the front-end decides how to render that data.
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Please don't store frontend specific things like this in the frontend backend. It should be available without communicating to the backend
If you really need this, then there might be a way to have a tool generate the relevant css on both sides
That said, why would the backend need to use frontend css? If this is because it depends on a state, why not use an enum instead?
don't do that. in case you'll decide to apply more complex restyling, everything will fall apart
I'd say normally you'd just have a switch somewhere in your js rendering that would assign the correct classes based on the status
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View