Combine C # int in .jpg

I am trying to concatenate the string src 4. I need to put empkey in src so that it gets the correct image. What is the correct way to concatenate this?

@foreach (var item in Model) { 
    <div class="container">
        <div class="empImage">
            <img src="EmpImages/@item.EmpKey +.jpg" style="float:left; border:1px solid #A4A4A4;" height="80" width="80">
        </div>
        <div class="forumTitle">
            @Html.DisplayFor(m => item.ForumTitle)
        </div>
        <div class="forumDate">
            @Html.DisplayFor(m => item.ForumDate)
        </div>
        <div class="forumPost">
            @Html.DisplayFor(m => item.ForumPost)
        </div>
    </div>
}
+4
source share
1 answer

You are pretty close, you just need parentheses to help MVC work where C # code ends.

<img src="EmpImages/@(item.EmpKey).jpg"

They are optional in all razor syntaxes, but in complex situations, the analyzer may get a little lost trying to guess if it is @(item).EmpKey.jpg, @(item.EmpKey).jpgor @(item.EmpKey.jpg), and the brackets allow you to be explicit about what you are after.

+6
source

Source: https://habr.com/ru/post/1538938/


All Articles