I am trying to execute this code
@model IEnumerable<Quiz.Services.Models.UserQuizViewModel>
@{
ViewData["Title"] = "Home Page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
</div>
<table class="table table-sm table-striped table-hover table-bordered">
<thead>
<tr>
<th>Quiz Name</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach (var quiz in Model)
{
<tr>
<td>@quiz.Title</td>
<td>
@if (quiz.QuizStatus == QuizStatus.NotStarted)
{
<a href="#" class="btn btn-success">Start Test</a>
}
else if (quiz.QuizStatus == QuizStatus.InProgress)
{
<a href="#" class="btn btn-warning">Continue Test</a>
}
else
{
<a href="#" class="btn btn-secondary">View Results</a>
}
</td>
</tr>
}
</tbody>
</table>
in the Index.cshtml file in my simple Asp.Net project. The problem is that the C# code is not working and when I type @
in the file I cannot use neither foreach
nor if-statement
.
This is my `UserQuizViewModel’
public int QuizId { get; set; }
public string QuizTitle { get; set; } = null!;
public QuizStatus QuizStatus { get; set; }
with QuizStatus
enum:
public enum QuizStatus
{
NotStarted = 0,
InProgress = 1,
Finished = 2
}
I thought that I had syntax errors but after some Google search I discover that this code should be valid and working. Should I install some NuGet Packages or something else in order to run this code? This is the content of _ViewImports.cshtml
file
@using Quiz.Web
@using Quiz.Web.Models
@using Quiz.Services.Models;
@using Quiz.Services.Models;
@using Quiz.Services.Models.Enums;
@using static Quiz.Common.GeneralApplicationConstants
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Ивайло Шопов is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.