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

230
Views
Obtenga la ruta de la imagen a src cuando la vista parcial carga ASP.NET MVC

Tengo esta etiqueta de imagen: <img src="url goes here" />

La acción de mi controlador se ve así:

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

userImage contiene algo como esto: ~/Content/img/users/userABCD.png

Ahora mi pregunta es, ¿cómo llamo al controlador y obtengo la ruta para poder pasarla a src ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

tal vez algo como esto:

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

ejemplo llamando desde otro controlador, "ControllerB" será el nombre real de su controlador ControllerB (parte receptora):

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

o puede intentar usar un ViewBag ?

 ViewBag.MyString = myString;

Entonces lo usarías como

 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!