Reputation: 57
I have an IEnumerable
view that returns a list of Remarks, but I also have a menu that has a link with a student number from a different entity that is linked to Remarks, it's hard to explain, so I'll post my code
<a href="@Url.Content("~/StudentGegevens/index/"+ Model.LRL_NR)" class="buttonStudentGegevens"><img src="../../images/ViewAccount.png"/> Student gegevens </a>
<a href="@Url.Content("~/StudentGegevens/MedischeInformatie/" [email protected]_NR)" class="buttonMedischeInformatie"><img src="../../images/ViewMedischeInfo.png"/> Medische informatie </a>
<a href="@Url.Content("~/StudentGegevens/BijlageenCommentaar/" [email protected]_NR)" class="buttonBijlagenCommentaar"><img src="../../images/ViewBijlage.png"/> Bijlage en commentaar </a>
a foreach(var item in Model)
wouldn't work because I only want the menu displayed once.
As you can see here, I give the student number to the link with @Model.LRL_NR
, but with an IEnumerable
view, you cannot do @Model.LRL_NR
, is there any way I can use @Model.LRL_NR
with an IEnumerable
view?
Upvotes: 0
Views: 256
Reputation: 499312
Iterate over your IEnumerable
and for each item in it write out the links:
@foreach(var item in Model)
{
<a href="@Url.Content("~/StudentGegevens/index/"+ item.LRL_NR)" class="buttonStudentGegevens"><img src="../../images/ViewAccount.png"/> Student gegevens </a>
<a href="@Url.Content("~/StudentGegevens/MedischeInformatie/" [email protected]_NR)" class="buttonMedischeInformatie"><img src="../../images/ViewMedischeInfo.png"/> Medische informatie </a>
<a href="@Url.Content("~/StudentGegevens/BijlageenCommentaar/" [email protected]_NR)" class="buttonBijlagenCommentaar"><img src="../../images/ViewBijlage.png"/> Bijlage en commentaar </a>
}
From your description, you need to access both LRL_NR
and the list of REMARK
.
One way to do this is to have a class that encapsulates them and that you use as your Model
:
public class RemarksModel
{
public int LRL_NR { get; set }
public IEnumerable<PvBempty.REMARK> Remarks { get; set }
}
This would allow you to do:
<a href="@Url.Content("~/StudentGegevens/index/"+ Model.LRL_NR)" class="buttonStudentGegevens"><img src="../../images/ViewAccount.png"/> Student gegevens </a>
<a href="@Url.Content("~/StudentGegevens/MedischeInformatie/" [email protected]_NR)" class="buttonMedischeInformatie"><img src="../../images/ViewMedischeInfo.png"/> Medische informatie </a>
<a href="@Url.Content("~/StudentGegevens/BijlageenCommentaar/" [email protected]_NR)" class="buttonBijlagenCommentaar"><img src="../../images/ViewBijlage.png"/> Bijlage en commentaar </a>
foreach(var item in Model.Remarks)
{
// each item is a PvBempty.REMARK
}
Upvotes: 1