Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to manage ASP.NET parameters and Javascript keys

So here is my scenario.

Im using ASP.NET MVC 3 along with HTML, CSS, JavaScript/JQuery to make a web application. Im using Visual Studio 2010

We have already released the product (its in 1.0), however now that we are in "maintenance" mode for the project, I have a feeling that as the project has new features added, that it will be harder to maintain the set of constants between both the C# (ASP.NET MVC) and the JavaScript.

For example, in the JavaScript I would create a $.post and have it link to the MVC url Controller/Action and then I would pass in parameters { key1: value1, key2: value2}

The issue is that if the C# parameter names change or if the position of parameters in the signature change, I will only know at run-time that the JavaScript needs to be updated (im assuming that im a programmer that doesn't know the architecture well enough to do this before run time).

So my question is, how do you manage the JavaScript side more easily so that i can stay "in-sync" with changes made on the C# side. Can the compiler do this for me in some way, or is there a plug-in that can help me out?

Thanks.


1 Answers

Your question asks about syncing C# constants and JavaScript constants, but then also talks about parameter names and positions.

The positions of parameters matter less in the MVC world than the names, and I've not found a good way of keep those in sync short of extensive unit and integration testing. You are doing those tests, right? ;)

As far as actual constants and enums, I've taken to using T4 templates to generate both a .cs and a (namespaced) .js file for the constants/enums I need (in my case, out of a database, but could just as easily be anything else).

like image 196
Heretic Monkey Avatar answered Nov 30 '25 16:11

Heretic Monkey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!