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?

Community
  • 1
  • 1
unkownt
  • 621
  • 2
  • 8
  • 18

2 Answers2

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.

ConsultUtah
  • 6,639
  • 3
  • 32
  • 51
0

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

In your Action method:

return JavaScript("javascript code");

ZippyV
  • 12,540
  • 3
  • 37
  • 52
  • 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 http://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. – unkownt Dec 20 '10 at 16:19
  • 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. – ZippyV Dec 20 '10 at 16:37