question

silverline-3137 avatar image
0 Votes"
silverline-3137 asked ChaoDeng-MSFT edited

I am developing CMS and have a problem to display employee's photo in "details" view as it is dynamic, how to assign a dynamic path to employee's photo?

in "details" view :

<div class="mb-3">
<span class="input-group-text" id="basic-addon3" asp-for="Photo_Form"> Your Photo </span>
<img src="@Url.Content(ViewBag.photo_details)" asp-append-version="true" class="img-circle" id="Photo_Form" name="Photo_Name" />

</div>



in "index" view, and it is working BTW ..
<td>@item.Id</td>
<td>@item.Name</td>
<td>@item.Salary</td>
<td>@item.Email</td>
<td>@item.HireDate.ToShortDateString()</td>
<td><img src="~/Files/Photos/@item.Photo_Name" width="100" height="100" /></td>
<td><a href="~/Files/Docs/@item.CV_Name" download="download">download content</a></td>
<td>@item.IsActive</td>
<td>@item.Notes</td>
<td>@item.department_nav_prop.DepartmentName</td>
<td>@item.DistrictId</td>



in employee's controller :

region details operation


     [HttpGet]
     public IActionResult Details(int id)
     {

         var rowDetailsData = newEmployeeMirror.Read_By_Id_Func(id);
         var convertedToMirror = newIMapper.Map<EmployeeMirror>(rowDetailsData);


         //here we need to check mapping :
         ViewBag.photo_details = rowDetailsData.Photo_Name;

         ViewBag.photo_path = @"~/Files/Photos/@ViewBag.photo_details";


         var allDepartments = newDepartmentMirror1.Read_All_Func();
         ViewBag.departmentList = new SelectList(allDepartments, "Id", "DepartmentName");

         return View(convertedToMirror);
     }

     #endregion


dotnet-aspnet-core-mvcdotnet-aspnet-core-blazor
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @silverline-3137,
You can try to write like this:

<img src="@Url.Content(String.Format("~/Files/Photos/{0}", item.Photo_Name))"

0 Votes 0 ·

0 Answers