1

I am writing a wizard to let users map strings to properties on an object. This is done by using some predefined rules that the user selects and supplies the arguments to. These collections of rules are saved to a database and run later via service calls.

The problem is that in the wizard I have it highlighting and updating some example text as the user selects the rules and types the arguments. This is done using JavaScript so obviously is duplicating the logic contained inside the C# rules.

So I'm looking for ways to get around this.

The rules are quite simple and just contain a list of arguments to apply and a single method that takes the input string and returns the result.

1

2 Answers 2

3

You can use AJAX to send the data to the backend, process it, and drop it in the right place. This wouldn't duplicate that logic then. You'll likely need to maintain a bit of JS code to keep the screen and the service attached though.

Sign up to request clarification or add additional context in comments.

3 Comments

I did consider AJAX calls but I'm not sure if they will be quick enough for the real time updating as the user types. Might use this as a last resort but I was more looking for something that can be run on both the server and client.
Maybe something like smp.if.uj.edu.pl/~mkol/il2js ? I've never used it, and I bet it only works for some minimum set of instructions but that's something. Additionally, you could attempt to run the same JS instructions in a JS engine within .NET.
Ended up just having all logic on the server and making ajax requests.
0

I have a similar situation with JavaScript and Java. My solution was to just use JavaScript: On the client, that's run by the browser. On the server, in my case, it's compiled with Rhino (JavaScript for the JVM), but it's the same source code in both cases.

The .Net platform supports JScript.Net, which is very similar to JavaScript. I expect without too much effort you could write the code once, in JavaScript, and have JScript.Net compile it into a module you could use server-side, alongside your C# code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.