Developer forum

Forum » Templates » Make Visual Studio recognize DW methodes

Make Visual Studio recognize DW methodes

Sten Hougaard
Reply

Hi,

The only valid path to code in Razor if you want proper development features like intellisense I guess is to use Microsoft Visual Studio.

I am editing a .CSHTML template and look closely at the "Error list" area of VS, also on errors inside the code and come across this one often: "The name 'GetLoop' does not exist in the current context". Guess that VS does not  recognize the DW "GetLoop".

Can I somehow add a "@using" to fix this annoying issue?

 

 

Med venlig hilsen/Best regards,

 

Sten Hougaard

Webudvikler

 

A: København/Aarhus . W: www.1stweb.dk

 

 

 

 

 


Replies

 
Morten Bengtson
Reply

Try this...

@using Dynamicweb.Rendering;
@model RazorTemplateModel<Template>

It seemed a bit buggy last time I tried, but it did provide some intellisense.

 
Sten Hougaard
Reply
Thanks Morten,

It is obvious (not!) :-) Anyway makes no difference in my VS.
I have opened the site using "Open website", perhaps that is why VS understands nothing...
Hmm... I am biting my tong now not so write some bad things about Razor being such backend... better stop! :-)

Anyway - thanks Morten, I will continue working with no one understanding my front-end razor code :-(


Med venlig hilsen/Best regards,

Sten Hougaard
Webudvikler

A: København/Aarhus . W: www.1stweb.dk
@: netsi1964
Thanks Morten,

It is obvious (not!) :-) Anyway makes no difference in my VS.
I have opened the site using "Open website", perhaps that is why VS understands nothing...
Hmm... I am biting my tong now not so write some bad things about Razor being such backend... better stop! :-)

Anyway - thanks Morten, I will continue working with no one understanding my front-end razor code :-(


Med venlig hilsen/Best regards,

Sten Hougaard
Webudvikler

A: København/Aarhus . W: www.1stweb.dk
@: netsi1964

ps: sorry about the monospaced font. This forum does not accept you to paste text into it... :-(
(which I did because this forum does not allow you to reply from your e-mail client to the forum)



 
Morten Bengtson
Reply
This post has been marked as an answer

I just played around with some Razor stuff in DW and here is what I did in order to get intellisense working properly:

1. Create a new project in visual studio ("ASP.NET Empty Web Application")

2. Right click on "References" in solution explorer and add references to Dynamicweb.dll and RazorEngine.dll

3. Add a new Razor template (just create an .html file and then rename to .cshtml)

4. Add the following to the top of the Razor template

@inherits RazorTemplateBase<RazorTemplateModel<Template>>
@using Dynamicweb.Rendering;

 

Now you should have intellisense. It works for me in Visual Studio 2012.

BTW: There is a "Paste as plain text" option in the forum editor ;-)

Votes for this answer: 1
 
Remi Muller
Reply
I tried using:

@inherits RazorTemplateBase<RazorTemplateModel<Template>>
@using System;
@using System.Linq;
@using Dynamicweb.Rendering;

 

The intellisense works in VS2012

 

In a Page and Masterpage template this inherits is not working for the DW tempalte parser. I get the folowing error:

Error compiling template "Designs/bootstrap_bluedesk/_parsed/home.parsed.cshtml"
Line 33: Type expected
Line 33: { expected
Line 33: Invalid token '<' in class, struct, or interface member declaration
Line 33: Invalid token '>' in class, struct, or interface member declaration

 

From the parsed html source:

1 <!DOCTYPE html>
2 <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
3 <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
4 <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
5 <!--[if gt IE 8]><!-->
6 <html class="no-js">
7 <!--<![endif]-->
8 <head>
9 <meta charset="utf-8">
10 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
11 <title>@GetValue("Title")</title>
12 @GetValue("MetaTags")
13 @GetValue("CopyRightNotice")
14
15 <meta name="viewport" content="width=device-width">
16
17 <meta name="author" content="Bluedesk">
18 <link href="/Files/Templates/Designs/bootstrap_bluedesk/css/bootstrap.css" rel="stylesheet">
19 <link href="/Files/Templates/Designs/bootstrap_bluedesk/css/bootstrap-responsive.css" rel="stylesheet">
20 <link href="/Files/Templates/Designs/bootstrap_bluedesk/css/bluedesk.less" rel="stylesheet">
21 <link rel="shortcut icon" href="/Files/Templates/Designs/bootstrap_bluedesk/img/favicon.ico">
22 <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/Files/Templates/Designs/bootstrap_bluedesk/img/apple-touch-icon-144-precomposed.png">
23 <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/Files/Templates/Designs/bootstrap_bluedesk/img/apple-touch-icon-114-precomposed.png">
24 <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/Files/Templates/Designs/bootstrap_bluedesk/img/apple-touch-icon-72-precomposed.png">
25 <link rel="apple-touch-icon-precomposed" href="/Files/Templates/Designs/bootstrap_bluedesk/img/apple-touch-icon-57-precomposed.png">
26 <script src="/Files/Templates/Designs/bootstrap_bluedesk/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
27 @GetValue("Stylesheets")
28 @GetValue("Javascripts")
29 </head>
30
31 <body>
32 <div class="container">
33 <div class="container-fluid">
34 <div class="row-fluid">
35 <div class="span4">
36 <a class="logo" href="index.html">
37 <img alt="logo" title="bizstrap" src="http://slvasoftech.com/images/logo.png">
38 </a>
39 </div>
...[deleted lines]...
93
94 <div class="container-fluid">
95 @inherits RazorTemplateBase<><template>>
96 @using System;
97 @using System.Linq;
98 @using Dynamicweb.Rendering;
99
100
101
102
103 <div>
...[deleted lines]...
142 </body>
143 </html>
 

Will this be fixed in DW or can i do something else?

 

 

 

 

 
Mikkel Ricky
Reply

Try adding spaces inside <…>, e.g. write

@inherits RazorTemplateBase< RazorTemplateModel< Template >>

Our layout template parser sometimes gets confused with Razor code that looks like html/xml (like <Template>).

 

 

 

 
Remi Muller
Reply

Thanks that works!

Shouldn't this be fixed in the template parser?

 

 
Mikkel Ricky
Reply

Yes, it should be fixed in the parser. We're using Html Agility Pack (http://htmlagilitypack.codeplex.com/) to parse layout templates, but Html Agility Pack does not recognize Razor.

We have to find another good way to pre-process Razor layout templates, but for now we have to live with this workaround.

 

 
Remi Muller
Reply

@inherits RazorTemplateBase< RazorTemplateModel< Template >>

It is still buggy even with spaces added.
With dw 8.3.1.8. It looks like when the solution is rebuild the initial template parsing on startup is still having trouble with the lines "inherits Razor..." containing extra spaces. I have to delete the parsed files and then it works again.

This is getting annoying when developing.

 

 Can we get a better fix or workaround soon?

 


 

 

 

 

 
Remi Muller
Reply

Is the new @Translate method part of RazorTemplateBase?

Because it is not being picked up by intellisense. Or is a namespace needed or something?

Thanks.

 
Mikkel Ricky
Reply

@Translate is not yet at real function, but it will be in Dynamicweb 8.5. Therefore it's currently not a part of RazorTemplateBase and it does not exist in any namespace.

See the forum post http://developer.dynamicweb-cms.com/forum/cms-standard-features/cannot-resolve-symbol-translate.aspx#Reply35967 for details.

Best regards,
Mikkel

 

You must be logged in to post in the forum