This project is read-only.

Adding a prefix to the generated class names

Dec 18, 2012 at 4:57 AM


If your project has lots of views and lots of HTML helpers, the name clashes start to pile up.

Is it possible to use the directive file to assign a prefix for the class name that will be generated?


Would it be possible to use unique, guid-like names for the view class names (NOT the helpers)

I was also wondering: I am using my own view engine, will this clash with the ViewEngine that is automatically added to the view engines collection?


Dec 18, 2012 at 11:23 PM

The generated classes are placed in a namespace that matches the folder structure, so having foo.cshtml in multiple folders should not cause conflicts, no matter how many views you have.

Using random names would not work well as it would change each time you generate the code, causing unwanted source control diffs (since they're normally committed).

No view engine is added automatically. This is done via explicit code in your App_Start\RazorGeneratorMvcStart.cs, which you can control whatever way you want (e.g. re-order, ...).

Dec 19, 2012 at 7:17 PM

You are right about the namespaces; the classes are in different namespaces but when the classes are used in the generated code, the namespaces are not included.

Dec 19, 2012 at 7:27 PM

Not quite following you here. It might be helpful if you share a sample repro (e.g. on Github) that demonstrates the problem.

Dec 19, 2012 at 10:15 PM

Hi David,

This is the code fragment from the generated.cs


#line 121 "..\..\Views\Shared\_ContentSectionEdit.cshtml"


The problem is that there's a helper called Info


"RazorGenerator", "" )]
public static class Info : TECHIS.EndApps.Web.MvcHelperPage

And, a View also called Info:

public class Info : System.Web.Mvc.WebViewPage<ExtendedModel>


  When a view using the helper is generated, the Info view then takes naming precedence, leading to a compile error.