Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
Get Image Path to src when partial view loads ASP.NET MVC

I have this image tag: <img src="url goes here" />

My controller action looks like this:

public string GetProfilePhotoPath(){
    var userId = User.Identity.GetUserId();
    var userImage = db.Users.FirstOrDefault(u => u.Id == userId).ProfilePhotoPath;
    return userImage;
}

userImage contains something like this: ~/Content/img/users/userABCD.png

Now my question is, how do I call the controller and get the path so I can pass it to src?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

maybe something like this:

<img src="@Url.Content("~/Content/img/users/" + ControllerB().GetProfilePhotoPath()" alt="" />

example calling from another controller, "ControllerB" will be the actual name of your controller ControllerB (receiving part):

var result = new ControllerB().GetProfilePhotoPath();

or you can try using a ViewBag ?

ViewBag.MyString = myString;

Then you would use it like

img src="@Url.Content("~/Content/img/users/" + @ViewBag.MyString" alt="" />
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!