i have an asp.net mvc website where i build up most of the page using C# for example building up html tables given a set of data from my viewmodel
i also have a lot of javascript that then dynamcially modifies these tables (add row for example).
the javascript code to add a new row looks extremely similar to my "rendering" code i have in C# that is used to build up the html table in the first place.
Every time i change the c# code to a add a new field, i have to remember to go back to the javascript code to do the same.
is there a better way here?
One way to do this is to expose the logic that generates the markup as a web service on your server and have JavaScript get that markup via an AJAX call rather than duplicating the logic.
This way you can call something like a CreateRow
method from JavaScript that will actually invoke the same exact logic that you used on the server when you rendered the page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With