Hi @Eddy Wu
The null reference exception relates the above code, in the OnGet method, you create a new DataSet instance and set the data for it, without setting the data for the MenuItems property of PageModel. So, in the view page, it will show the null reference exception.
To solve this issue, change your code as below:
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public DataSet MenuItems { get; set; }
public void OnGet()
{
... // in the using statement.
MenuItems = new DataSet();
sda.Fill(MenuItems);
...
}
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion