Jump to content

Como colocar na view uma imagem que esta numa pasta atraves do nome que esta na base de dados


rsd_17

Recommended Posts

Ola, 

Estou a tentar apresentar na view a foto do utilizador mas na base de dados no campo fotografia apenas tenho guardado o nome da fotografia, mas a fotografia esta guardada na pasta Fotos em wwwroot. Ha alguma forma de apresentar a imagem buscando o nome a base de dados e o resto do caminho ? 

Algo assim ? Mas nao funciona ... 


<img src="~/Fotos/@Html.DisplayFor(modelItem => item.Fotografia)/>

Tenho isto na View :

<table class="table">
    <thead>
        <tr>
            <th>

            </th>
            <th>
                @Html.DisplayNameFor(model => model.Nome)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Email)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Telefone)
            </th>

            <th>
                @Html.DisplayNameFor(model => model.Sexo)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Especialidade)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Estado)
            </th>
            <th>
                @Html.DisplayNameFor(model => model.Password)
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
        <tr>
            <td>

                <img src="~/Fotos/" + "@Html.DisplayFor(modelItem => item.Fotografia)" />
            </td>
            <br/>
            <br/>
            <td>
                @Html.DisplayFor(modelItem => item.Nome)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Email)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Telefone)
            </td>

            <td>
                @Html.DisplayFor(modelItem => item.Sexo)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Especialidade)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Estado)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Password)
            </td>
            <td>
                <a asp-action="Edit" asp-route-id="@item.Idprofessor">Edit</a> |
                <a asp-action="Details" asp-route-id="@item.Idprofessor">Details</a> |
                <a asp-action="Delete" asp-route-id="@item.Idprofessor">Delete</a>
            </td>
        </tr>
        }
    </tbody>
</table>

Ha alguma forma de colocar a imagem na view desta forma ? 

Link to comment
Share on other sites

O teu IMG tem de referenciar o caminho ao nível do servidor web, não do file system.
Quando metes o caminho da imagem no browser vais ver a imagem, é isso que tens de usar para a tag IMG.

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.