It turns out that your Razor views are not to be writen in exactly the same way as when running within an ASP.NET web context. I suppose I should have guessed this from the way I was used to declaring the model for the WebFormsViewEngine.
Solution
Instead of using the@model
declaration at the the top I should have been using @inherits
. An example:Regular Razor view for web:
@model Models.ContactDetailsViewModel <!DOCTYPE html> <html> <body> <div> <p>Hello @Model.FullName,</p> <p>We will call you at @Model.CallTime on @Model.PhoneNumber</p> <p>Thanks</p> </div> </body> </html>
Razor view for use as a template:
@inherits RazorEngine.Templating.TemplateBase<Models.ContactDetailsViewModel> <!DOCTYPE html> <html> <body> <div> <p>Hello @Model.FullName,</p> <p>We will call you at @Model.CallTime on @Model.PhoneNumber</p> <p>Thanks</p> </div> </body> </html>
Hope this helps and well done for using such an awesome feature of the RazorEngine!
Hi
ReplyDeleteThanks for the info, this solved the compile problem, however I no longer get intellisense in VS2010. In the cshtml file the intellisense tells me that a reference is missing to the RazorEngine assembly.
Did you get this problem?
I added the RazorEngine using NuGet so it got all the references for me and it all works well so I can't say I recognise your issue. I'm using VS2010 SP1 if that helps.
ReplyDeleteThe @model keyword is specific to ASP.NET MVC3's RazorViewEngine. The base parser itself doesn't support it, but it does support adding custom keywords. Visual Studio using @model out of the box to support its Intellisense feature (it can use either @inherits or the terse @model).
ReplyDeleteYou can manually add support for this in RazorEngine v2 but you'd need to recompile it. I'm hoping to introduce a generic keyword extension mechanism in v3 which should easily enable these scenarios.
Thanks for the info Matthew. But much more importantly thanks for making the Razor Engine!
ReplyDeleteFYI, @model has been implemented in v3, which I am hoping to push onto GitHub soon :-)
ReplyDeleteSaved my day. Thank you! Thank you very much!!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI get a TemplateCompilationException but it is on my model type, not on the model keyword. I get the same exception when I change it to "@inherits RazorEngine.Templating.TemplateBase<MyType>". Any pointers there?
ReplyDeleteI resolved the issue I was having. I was not fully-qualifying MyType. After fully qualifying it, e.g. "@model ModelNamespace.MyType", it now works. This blog was helpful: http://mehdi.me/generating-html-emails-with-razorengine-basics-generating-your-first-email/
ReplyDeleteGreat ARticle
ReplyDeleteMotifz Designer Lawn. 1, 2 & 3 Piece Unstitched Premium Embroidered Lawn 2019, Premium embroidered Lawn, Premium lawn, Premium lawn 2019, Motifz, Premium lawn in Pakistan. Shipping worldwide. Stitching option available.
ReplyDeleteNice Post.
ReplyDeletehttps://forum.parallels.com/threads/unable-to-connect-outlook-to-office-365-since-reboot.346498/
https://community.constantcontact.com/t5/Need-help-with-something-else/Tab/td-p/314570/page/2
https://www.prestashop.com/forums/topic/956372-white-page-in-prestashop/
https://community.teamviewer.com/t5/TeamViewer-General/Will-not-connect-to-partner-computer-Team-Viewer-14-1-18533/td-p/56122
https://communities.vmware.com/message/2843114
A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one. hyip templates
ReplyDeleteThe writer is enthusiastic about purchasing wooden furniture on the web and his exploration about best wooden furniture has brought about the arrangement of this article. hyip templates
ReplyDeleteActivate Trendmicro - Follow steps to download, install, and activate Trend Micro product. Type the product key by clickingtrendmicro.com/activation.
ReplyDeleteMagic ISO Maker Crack containing exact binary copies of the original CDs. Usually, you have to burn an ISO file on a CD to extract its contents, but now you can simply open an ISO file in MagicISO. Magic ISO Maker 2016 Serial Key can make bootable CD/DVD picture document. With Magic ISO, you can prepare the boot data for CD/DVD picture document, and straightforwardly include/ evacuate/ separate boot picture for the CD/DVD picture record. Download Magic ISO Maker Build 281 Full Serial Key 2016 from here.MagicISO Maker Serial Key is an awesome application that can be used for creating and editing disk images. The interface if he application is very catchy and its explorer based layout makes it easy to navigate. In addition to being able to edit the contents of the disc images without decompressing, it can make a disc image from an existing CD/DVD-ROM. Also, it can make bootable image files (file extension. bif). MagicISO Maker Latest Version can mount disc images with the addition of MagicISO Virtual CD/DVD Manager. with Magic ISO Maker you can burn the image files onto CD-R, CD-RW, DVD-R, DVD-RW. You can also compress and decompress image files as well. Magic ISO Maker can handle upto 10GB of DVD images. All in all Magic ISO Maker Keygen is a very useful and can be used for creating the image files as well as for extracting the content from the image files.
ReplyDeleteSuch a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. website builder easy free
ReplyDeleteThrough this post, I know that your good knowledge in playing with all the pieces was very helpful. I notify that this is the first place where I find issues I've been searching for. You have a clever yet attractive way of writing. website builder godaddy
ReplyDeleteWe are really grateful for your blog post. You will find a lot of approaches after visiting your post. Great work gadgetdeep pocket
ReplyDeleteI think I have never seen such blogs ever before that has complete things with all details which I want. So kindly update this ever for us. iphone 11 cases
ReplyDeleteI have checked this link this is really important for the people to get benefit from. free english course online video
ReplyDeleteThis post is very simple to read and appreciate without leaving any details out. Great work! Short Term Rental Missouri
ReplyDeleteMmm.. good to be here in your article or post, whatever, I think I should also work hard for my own website like I see some good and updated working in your site. Registered dietitian
ReplyDeleteTruly, this article is really one of the very best in the history of articles. I am a antique ’Article’ collector and I sometimes read some new articles if I find them interesting. And I found this one pretty fascinating and it should go into my collection. Very good work! LED mini mirror
ReplyDeleteCool stuff you have and you keep overhaul every one of us rechargeable LED
ReplyDeleteThis is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. thomasjefferson
ReplyDeleteI quite like reading an article that can make people think. Also, thanks for allowing for me to comment! Revitalizing
ReplyDeleteYour blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging, demeter cologne spray
ReplyDeleteI’m usually to blogging and i really admire your content. The article has really peaks my interest. I am going to bookmark your web site and keep checking for brand spanking new information. logo designers
ReplyDeleteYou’ll find some fascinating points in time in this post but I do not know if I see all of them center to heart. There’s some validity but I will take hold opinion until I appear into it further. Fantastic post , thanks and we want much more! Added to FeedBurner too new york web designs
ReplyDeleteI am very glad after reading your blog , Thanks for shring .
ReplyDeletewindows-10
ipad
iphone
firefox
sensorexplorer2.0
facebook
Islam, one among largest religions in the world also the one that is misunderstood all time. There are several sources including political, economic & media, framed Islam as misleading religion. And the truth about muslims are always hidden from the light.
ReplyDeleteTruth About Islam
Truth About Muslims
Islamic Sharia Law
Women In Islam
Why Wear Hijab
Quran And Science
Muslims Are Not Terrorists
Polygamy In Islam
the holy book of islam
Buy online wholesale printed custom lipstick boxes and packaging at easy prices and shipping worldwide, with 24/7 customer support. Get a free custom quote now!!
ReplyDeleteThinking pessimistic sides of the things makes us hopeful so that I would like to suggest to all the readers that they must keep an eye on the positive sides of the things for getting success in their life. Assignment Writing Service
ReplyDeletePackaging town is a one-stop solution for the short-run cbd tincure boxes needs, and supplies. At affordable prices. Request a free quote now.
ReplyDeleteSuch a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. Doge
ReplyDeleteJS Removals offer professional home removal services & rubbish clearances for the East Midlands. With hundreds of 5* Reviews book with confidence. moving company
ReplyDeletebuy tshirts for men online from dshred at easy prices delivered at your doorstep. Get free shipping
ReplyDeleteThanks for sharing a particularly decent data through this blog. I trust it will help everybody. I like your work, kindly continue to share. We are the main online instructive gateway that gives assignment composing administrations particularly to understudies.
ReplyDeleteassignment help
Open the software utility that manages your wireless connections on the computer or wireless device that you want to connect to your router. Using Netgear WNDR4720 Manual, you can setup your router. This utility scans for all wireless networks in your area. Find and select your wireless network name (SSID). The SSID is located on the product label.
ReplyDeleteBuy shorts for men from ndure at best prices delivered at your doorstep. Get free shipping
ReplyDeleteBuy women cotton tees online from ndure at easy prices delivered at your doorstep. Get free shipping
ReplyDeleteBuy grocery online from Al-Fatah at best prices delivered at your doorstep. Get free shipping
ReplyDeleteThe given article covers all the important and necessary details for the topic so thanks for sharing this information! it was very informative and helpful!
ReplyDeletemyassignmenthelp
Buy men clothing online in Pakistan from Al-Fatah at best prices delivered at your doorstep. Get free shipping.
ReplyDeleteI like this post. Are you in need of custom thesis writing help at affordable rates? Let us help you, we offer top-quality writing hel online.
ReplyDelete