开发者

Insert Razor text into string from Model

开发者 https://www.devze.com 2023-04-07 11:18 出处:网络
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:

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" tar开发者_StackOverflow社区get="_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">
  }


@foreach (var item in Model)
{
    <a href="@Html.AttributeEncode(@Url.Content("~/PDFFiles/" + item.Filename + ".pdf#page=" + item.PageNum))" target="_blank">Download</a>
}


Just prefix your variable name with @

@foreach (var item in Model)
{
  <a href="/PDFFiles/@(item.Filename).pdf#page=@(item.PageNum)" target="_blank">
}
0

精彩评论

暂无评论...
验证码 换一张
取 消