Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda