Bilal Tüylü
Bilal Tüylü

Reputation: 19

How to use RazorGenerator in project?

I want to use RazorGenerator for partial views between project in MVC. I have searched many websites but I can't find it anywhere. I have added the NuGet package to my project and after what am I doing? Please help. Thank you.

Upvotes: 0

Views: 8844

Answers (1)

bilpor
bilpor

Reputation: 3921

You need to do the following:

  • Go to an MVC Razor view's property and set the Custom tool to RazorGenerator
  • Optionally specify a value for Custom Tool Namespace to specify a namespace for the generated file. The project namespace is used by default.
  • Optionally specify one of the generators in the first line of your Razor file. A generator declaration line looks like this: @* Generator: MvcHelper *@ . If you don't specify this, a generator is picked based on convention (e.g. files under Views are treated as MvcViews)
  • You'll see a generated .cs file under the .cshtml file, which will be used at runtime instead of the .cshtml file
  • You can also go to the nuget Package Manager Console and run 'Enable-RazorGenerator' to enable the Custom Tool on all the views.
  • And to cause all the views to be regenerated, go to the nuget Package Manager Console and run 'Redo-RazorGenerator'. This is useful when you update the generator package and it needs to generate different code.

More can be found at Razor Generator

Upvotes: 5

Related Questions