HtmlTemplateBase

Feb 10, 2011 at 10:32 PM

The current release doesn't seem to contain HtmlTemplateBase.  Where can I find an example of this that will work with 2.1?  I tried to yank a version of HtmlTemplateBase out of an older release but it doesn't seem to be compatible.

Thanks!

Coordinator
Feb 10, 2011 at 10:43 PM

Hi,

The HtmlTemplateBase<T> was an example template that demonstrates how to build a custom base template; it's not an official part of the base RazorEngine project. I'll try to get round to release some additional template bases to target specific scenarios, perhaps to accompany the v2.2 release.

Feb 11, 2011 at 3:47 PM

Thanks for the quick reply!  Do you have an implementation of HtmlTemplateBase that works in 2.1?  I attempted writing it myself, but I don't know that I have what it takes.

Coordinator
Feb 11, 2011 at 5:03 PM

I'll chuck something together for you tonight.

Mar 7, 2011 at 2:51 PM

Bump.  Sorry to be a bother, but I really wanted to make use of MVC's HTML Helpers and can't for the life of me get it working in 2.1. =[

Mar 12, 2011 at 10:26 PM

Hi,

Did you solve it?

I did not get it running - when  using Html.LabelFor(m=>m.Companyname) the result being rendered is always "Companyname" instead of the value of Companyname...

Alex

Coordinator
Mar 14, 2011 at 9:26 AM

Sorry guys, I still haven't got round to looking at this, its on my (very big) todo list though.

Apr 28, 2011 at 9:32 PM

Not news on this yet? Thanks to everybody for the wonderful work on this, but a default implementation of the HtmlTemplateBase<> would take this framework to a whole new level!

 

Miguel

Sep 29, 2011 at 3:11 PM

I just put together an implementation of HtmlTemplateBase<> that supports Html Helper and the ViewBag. Can be easily extended to have Ajax helper etc. Here is the details:

http://www.haiders.net/post/HtmlTemplateBase.aspx

Sep 29, 2011 at 3:48 PM

Thanks Haider!

Dec 26, 2015 at 9:39 AM
Haider i am followed your blog and try to implement razorengine i am getting error, please guide me

Below code is not working
I have created HtmlTemplateBase class and model class with name, email and copy paste the below i am getting error. error CS1061: 'System.Web.Mvc.HtmlHelper<MvcApplication5.Controllers.PageModel>' does not contain a definition for 'TextBoxFor' and no extension method 'TextBoxFor' accepting a first argument of type 'System.Web.Mvc.HtmlHelper<MvcApplication5.Controllers.PageModel>' could be found (are you missing a using directive or an assembly reference?)}

please help me

Razor.SetTemplateBase(typeof(HtmlTemplateBase<>));

string template =
@"<html>
<head> <title>Hello @Model.Name</title> </head> <body>
Email: @Html.TextBoxFor(m => m.Email)
</body>
</html>";
var model = new PageModel { Name = "World", Email = "someone@somewhere.com" };
string result = Razor.Parse(template, model);