The 'inherits' keyword is not allowed when a 'model' keyword is used
Asked Answered
Z

1

9

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

 public EmailResult TestEmail(EmailModel model)
    {
        To.Add(model.Email);
        From = "[email protected]";
        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://mcmap.net/q/268523/-the-view-must-derive-from-webviewpage-or-webviewpage-lt-tmodel-gt

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

Zielinski answered 11/1, 2014 at 9:43 Comment(8)
try @inherits System.Web.Mvc.WebViewPage<W2G.Models.EmailModel>Littlefield
@KhanhTO I have tried it but now I have this error "The view must derive from WebViewPage, or WebViewPage<TModel>."Zielinski
did you declare the generic type <W2G.Models.EmailModel>?Littlefield
Are you using it inside of MVC or its external class which use razor?Joh
It's a external ActionMailer.Net.Mvc class which I am usingZielinski
@can you share class Email?Joh
@VolodymyrBilyachat It's ActionMailer DLL you can download from nugetZielinski
@Dilip0165 got it, i just post answer can you check it? if it does not help then i will try to do it when back homeJoh
J
14

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

Joh answered 11/1, 2014 at 11:21 Comment(2)
or somewhere in your cshtml file you have written "@model" instead of "@Model"Gherkin
The code above did properly use "@model". This solution works perfectly well. +1.Jessalyn

© 2022 - 2024 — McMap. All rights reserved.