0

Here is the example:

<script> function getString(){ var a = "something"; return a;} </script>

and razor example:

string a = "javascript return" or getString();

is that possible?

2
  • if this javascript loading off the bat it may be possible to store the javascript variable as a tempData/sessionData, then set your razor variable equal to that (viewbag/tempdata) "on load", but if it does not occur on load then I do not think it is possible as razor turns into regular DOM once it spits out its code. Commented Mar 3, 2015 at 14:50
  • This script actually runs on page load, so can you write me a sample of assigning tempData to razor variable? Commented Mar 3, 2015 at 14:59

1 Answer 1

1

You wont be able to convert JavaScript variable/function call to a Razor variable. Razor variable is handled by Razor engine on server where as JavaScript on the other hand is a client side language running on the client.

Razor is a view engine used by the ASP.NET MVC framework running on the server to produce some HTML template.

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

1 Comment

The point is that i want to take time offset with javascript, and return it to razor, actually i did created script, and also a razor code which takes string as hours, when i hardcode it, works perfectly, javascript also returns what i want as alert, so i wanted to know if i can combine them and get the point. However thank you for your fast response.

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.