Question display dynamic photo in "details" view?

shiccorama

Member
Joined
Apr 24, 2021
Messages
6
Programming Experience
1-3
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 phot

in "details" view :

HTML:
<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 ..
HTML:
<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​


C#:
[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);
}
 
Last edited by a moderator:
Firstly, I have formatted your code for you. Please do it yourself in future. It makes your post far more readable.

Secondly, please don't use the title to provide the problem explanation. Provide a FULL and CLEAR explanation of the problem in your post and then write the title last, as a summary of your post.
 
As for the issue, given that you haven't provided a proper description of the issue, I'm going to make an educated guess that what you mean is that this:
C#:
ViewBag.photo_path = @"~/Files/Photos/@ViewBag.photo_details";
should actually be this:
C#:
ViewBag.photo_path = $@"~/Files/Photos/{ViewBag.photo_details}";
and this:
HTML:
<img src="@Url.Content(ViewBag.photo_details)" asp-append-version="true" class="img-circle" id="Photo_Form" name="Photo_Name" />
should actually be this:
HTML:
<img src="@Url.Content(ViewBag.photo_path)" asp-append-version="true" class="img-circle" id="Photo_Form" name="Photo_Name" />
 
It works, I cannot thank you enough.
As for the formation of the code, pardon me , this is my second question in all forums and I just read a couple guide lines about it.
Secondly, I read once that you can describe the problem in the title to save time for the developers, but anyway, I will follow your guidelines in the future.
Thirdly, your educated guess is brilliant, that's exactly my issue, and I tried it on my code and it worked like charm .
Finally, thanks a million for help.
 
As for the formation of the code, pardon me , this is my second question in all forums and I just read a couple guide lines about it.
Formatting is very important because reading unformatted code is unpleasant at best and difficult at worst, especially on mobile devices.
Secondly, I read once that you can describe the problem in the title to save time for the developers, but anyway, I will follow your guidelines in the future.
Some elsewhere may have other ideas but not here, please. A clear, descriptive title is important because it allows people to decide what is relevant to them without having to open and read every thread. That's at a high level though. The full description of the problem - what you want to do, how you're trying to do it and what happens when you try - should always be in the thread itself. You obviously don't have to but, as I said, I strongly suggest that you write the title last. Once you have written your full and clear description of the problem, summarising it in a title will be that much easier.
 
Back
Top Bottom