0

I am trying to use razor pages to make an asp.net core v. 2.0 website.

And I want to get an ipaddress from the C# code and use it to call a webapi from javascript. - but I'm stuck on showing an alert from javascript

basically my C# is that simple.

 class Aclass {
  public string Text{get;set;}
 }

and the javascript is like this:

    var text = @Model.Text;
    alert (text);

( and I have the model set for the page..)

does anyone know how to get the Text to show?

2 Answers 2

4
<script>
var text = '@(Model.Text)';
    alert (text);
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

the javascript fix was found here: Using Razor within JavaScript

basically it is a combination of '@ and ( that makes it all work.

var text = '@(Model.Text)'; alert(text);

and boom your flying..

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.