1

On my aspx view, I would like to generate javascript where some parts are generated:

before generation:

<script type="text/javascript">
    var A = 'an id';
    var B = "http://www.yahoo.com" + <%= Model.pathname %>;
</script>

After generation:

<script type="text/javascript">
    var A = 'an id';
    var B = "http://www.yahoo.com/videos/index.htm" ;
</script>

is this possible? what options do I have?

4 Answers 4

2

I suggest the following code:

<script type="text/javascript">
    var A = 'an id';
    var B = "http://www.yahoo.com<%= Model.pathname %>";
</script>

Maybe the IntelliSense is not completely right in Visual Studio, but it will work.

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

1 Comment

Why the shock MedicineMan? This seems similar to what one could do in classic ASP in some ways.
0

yes, it's entirely possible, javascript is not executed untill way after all of this stuff is rendered, you have pretty much whatever options you can imagine.

Comments

0

Yes this should work fine, just surround the directive with single quotes for example:

<script type="text/javascript">
    var A = 'an id';
    var B = "http://www.yahoo.com" + '<%= Model.pathname %>';
</script>

Comments

0

Yes, that's possible.

If the JavaScript code is in your view, then simply doing the: <%= Model.pathname %> would work.

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.