0

I'm new to using Razor and ASP.NET.

I currently have a site I'm trying to port over that heavily uses Javascript functions to manuipulate items on a HTML page.

Is it possible to use Razor syntax instead? How do you get DIV and other elements on a page? I'm using ASP.NET Web Pages.

Thanks for any help.

Alex Guerin
  • 2,336
  • 10
  • 36
  • 53
  • 1
    Can you update your question with some sample code and tell us exactly what you are trying to look for? You have mentioned JavaScript, Razor engine and regular Asp.Net web forms in your question. If you can provide some code and tell us exactly what you want, then it will be helpful for others to understand. – Pawan Mishra Nov 23 '11 at 03:22

2 Answers2

0

You can embed Razor syntax oriented code inside script blocks. Following are some threads that address the same problem :

Asp.Net MVC3 RC Razor views : syntax for embedding code inside <javascript> block

Using Razor within JavaScript

Razor Syntax and Javascript

Community
  • 1
  • 1
Pawan Mishra
  • 7,212
  • 5
  • 29
  • 39
0

No, Razor cannot easily replace heavy use of javascript (i.e. a web based app) without a complete rewrite of the Html app moving functionality from the client side to the server side.

You are probably best to learn javascript or determine what the underlying requirements were and re-write in Razor.

Potentially replacing javascript with tidier javascript might help, if you look at the likes of Knockoutjs and Jquery Templates maybe that might ease your pain.

JTew
  • 3,149
  • 3
  • 31
  • 39
  • I'd much prefer server-side to begin with. How would I go about selecting elements? – Alex Guerin Nov 23 '11 at 03:25
  • You have to use a mixture of Razor and Javascript, you'll never get a full replacement. Can you provide a sample of the html/js that you are trying to replace with Razor . – JTew Nov 23 '11 at 19:52