I have this class
public class Questionnaire
{
public List<Question> Questions { get; set; }
public Question this[int i]
{
get { return Questions[i]; }
}
}
And I'm trying to use it on my page with
Questionnaire questionnaire;
protected override async Task OnInitAsync()
{
questionnaire.Questions = new List<Question>();
}
But I just keep getting
'Questionnaire' does not contain a definition for 'Questions' and no extension method 'Questions' accepting a first argument of type 'Questionnaire' could be found (are you missing a using directive or an assembly reference?)
I noticed that I can seem to call
questionnaire.QuestionNumber = 1;
Even though I removed the QuestionNumber
property ages ago.
Following the reference I can see that in Questionnaire.g.i.cs
there is a QuestionNumber
property but no Questions
property.
I tried restarting VS, cleaning project, rebuilding the project but this achieved nothing.
I suspect that you have a page that is also called Questionnaire (Questionnaire.cshtml). In Blazor apps each .cshtml file is used to generate a class at build time that has the same name as the .cshtml file. So you probably have two Questionnaire classes: the one you defined yourself, and the one generated from the Questionnaire file. Renaming one of the two classes should fix the issue.