My problem is that I want to hide the @Html.ActionLink from this view:
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Subject.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.State.Description)
</th>
<th>
@Html.DisplayNameFor(model => model.Subject.Exams.FirstOrDefault().StartDate)
</th>
<th></th>
</tr>
@foreach (var item in Model.Subjects) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Subject.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.State.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.Subject.Exams.FirstOrDefault().StartDate)
</td>
<td>
@if ()
{
@Html.ActionLink("Inscribirse", "Register", new { id = item.StudentSubjectId })
}
</td>
</tr>
}
That has the model:
namespace Academica.Models.StudentExamViews
{
[NotMapped]
public class SearchView : StudentSubject
{
public List<StudentSubject> Subjects { get; set; }
}
}
And the controller the next action:
public ActionResult Index()
{
var student = db.Students.Where(u => u.UserName == User.Identity.Name).FirstOrDefault();
var subjects = db.StudentSubjects.Include(ss => ss.Subject.Exams).Where(ss => ss.StudentCareer.Student.StudentId == student.StudentId &&
ss.ExamEnabled == true).ToList();
var view = new SearchView
{
Subjects = subjects,
};
return View(view);
}
and there is the BD: What I need is to hide the @Html.ActionLink "Register" when I have a record in the StudentExams table with the same StudentSubjectId that corresponds to each foreach item With the register button the records are saved in the StudentExams table with its respective StudentSubjectId (from the controller's other actions)