So, when working with a Razor Class Library (RCL) in .NET Core 3.1 I'd like to have a predefined Index.cshtml file. And I would like it to use an AbstractIndexModel as its model, but this gives me errors.
basically i want to do something like this:
these two are in the RCL
public abstract class AbstractIndexModel : PageModel
{
public IActionResult OnGet()
{
return Page();
}
public abstract string Greeting { get; }
}
The razor html
@page
@model AbstractIndexModel
@model.Greeting
And then on to the app, where we have an implementation of our abstract class:
public class IndexModel : AbstractIndexModel
{
public override string Greeting => "Hello Stackoverflow!";
}
But this merely gives an error:
A suitable constructor for type 'Sample.Pages.AbstractIndexModel' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.
I guess this happens because the model we set is not 'concrete' (its an abstract class) But I would suppose using the @inherit instead of @model would then do the trick. It does not. Any suggestions?