Reputation: 1031
Can anyone help me with some Razor syntax? I have a foreach loop ( shown at the end) and I would like to insert two items of text into a link to produce something like this:
<a href="/PDFFiles/Dummy.pdf#page=123" target="_blank">
I hope my question is clear, Many thanks.
@foreach (var item in Model)
{
<a href="/PDFFiles/**item.Filename**.pdf#page=**item.PageNum**" target="_blank">
}
Upvotes: 0
Views: 4170
Reputation: 1038710
@foreach (var item in Model)
{
<a href="@Html.AttributeEncode(@Url.Content("~/PDFFiles/" + item.Filename + ".pdf#page=" + item.PageNum))" target="_blank">Download</a>
}
Upvotes: 3
Reputation: 69953
Just prefix your variable name with @
@foreach (var item in Model)
{
<a href="/PDFFiles/@(item.Filename).pdf#page=@(item.PageNum)" target="_blank">
}
Upvotes: 3