0

I am new to web development. I am using jquery templates and they work fine. However, I have a markup code which has stuff like this among other things:

@Html.ActionLink("MyAction", "MyControllerAction", "MyController")                
<div class="date">
     Posted on : ${DatePosted}
     <br />
     Modified on: ${DateModified}
     <br />
</div>

Now, the razor syntax above is of course not going to be interpreted correctly on client side. Is there any way to make razor syntax work in a jquery template? Any alternative way other than hard-coding the anchor? Does it even provide any benefit, using the html helper in the template?

Thanks!

1 Answer 1

3

Javascript does not read any razor syntax, it only reads plain HTML. Razor syntax is code executed on the server, before the resulting HTML is delivered to the browser. Javascript runs on the browser, after it has been delivered HTML content from the server. You are perfectly fine doing this:

<div class="date">
     @Html.ActionLink("MyAction", "MyControllerAction", "MyController")
     Posted on : ${DatePosted}
     <br />
     Modified on: ${DateModified}
     <br />
</div>

By the time Javascript gets access to this block, it will look like this:

<div class="date">
     <a href="/MyController/MyControllerAction">MyAction</a>
     Posted on : ${DatePosted}
     <br />
     Modified on: ${DateModified}
     <br />
</div>
Sign up to request clarification or add additional context in comments.

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.