0

For rails developer please check my last paragraph.

Is there an equivalent of escape_javascript in rails for .net specifically .net mvc2? I am going to return some JavaScript which needs to be escaped since I am getting the code from another view using RenderPartialViewToString http://craftycodeblog.com/2010/05/15/asp-net-mvc-render-partial-view-to-string/

You can see what escape_javascript does here Why escape_javascript before rendering a partial? if your not familiar with its functionality.

Rails developers: It feels like this function should be easy to implement or port for rails so can someone explain what it does more than just escaping qoutes?

2 Answers 2

1

If you go here, and click on the show source link, you can see the source to the method. It is just a Regex.Replace() call.

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

Comments

0

ASP.NET MVC provides 9 ActionResults, one of them is the JavascriptResult.

In your Action method:

return JavaScript("javascript code");

2 Comments

But I want to write my javascript code in a view and I also want to be able to use partials for the javascript code which needs to be escaped. Check out railscasts.com/episodes/136-jquery to see what I want to do if you are interested in a nicer solution than returning javascript from your action.
Now I understand. You have the same problem as I have, but I haven't found a solution yet. Since MVC can be extended you could try creating your own ActionResult.

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.