The keyword 'inherits' is not allowed when using the keyword 'model'

Hey. I am trying to call a RazorEmail template from my controller, as shown below.

public EmailResult TestEmail(EmailModel model) { To.Add(model.Email); From = " test@test.com "; Subject = "Testt Mail"; return Email("EmailTemplate", model); } 

in mind that my template is under

 ~/Views/Template/EmailTemplate.html.cshtml @inherits System.Web.Mvc.WebViewPage @model W2G.Models.EmailModel 

First, when I try to access, I have the following error

 The view must derive from WebViewPage, or WebViewPage<TModel>. 

I got the solutions from here https://stackoverflow.com/a/464632/

But now I get this error. Please kindly help me. It took me a long time

+7
c # asp.net-mvc razor razorengine
source share
1 answer

If you use a view in the mvc scope, then @inherits is equivalent to @model

Generally speaking, when you use

 @inherits MyWebViewPage<dynamic> 

this means your @Model variable will have a dynamic class if you use

 @model dynamic 

I don’t have all the ideas about your project and implementation, but try to remove the inheritance (it should get it from web.config, which you keep in the Views folder)

But when you use appearance (so the razor does not read your web.config), you must specify the base class

 @inherits System.Web.Mvc.WebViewPage<W2G.Models.EmailModel> 

read this article.

+11
source share

All Articles