Search code examples
c#asp.net-mvcrazorrazorengine

The 'inherits' keyword is not allowed when a 'model' keyword is used


Hi I am trying to call RazorEmail Template from my Controller as below

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

in view my Template is Under

~/Views/Template/EmailTemplate.html.cshtml 

@inherits System.Web.Mvc.WebViewPage

@model W2G.Models.EmailModel

First when I trying to access I have following error

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

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

But now I am getting this error . Please kindly help me . It took my lots of time


Solution

  • If you use view in mvc scope @inherits is equivalent of @model

    Generally speacking when you use

    @inherits MyWebViewPage<dynamic>
    

    this means that your @Model variable will be of class dynamic same would be if you use

    @model dynamic
    

    I dont have all view of you project and implementation but try to remove inherits (it should get it from web.config which you hold in Views folder)

    But when you are using outside (so razor cant read you web.config) you should specify base class

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

    read this article please