문제

I'm a beginner with ASP.NET MVC and I'm trying to set the src of an image with razor in a asp.net MVC website using an If statement.

this code works :

 <img src="@Url.Action("GetPersonPhoto", "Home", new RouteValueDictionary( new { cardid = "696969" }) )" />

I want to add :

@if(Model.HavePhoto)

And set the src to :

"~/Content/images/header-logo.png"

if HavePhoto is false...

How can I do it ?

도움이 되었습니까?

해결책

    var source= "~/Content/images/header-logo.png";
    @if(Model.HavePhoto)
    {
       source= Url.Action("GetPersonPhoto", "Home", 
                   new RouteValueDictionary( new { cardid = "696969" }))
    }

    <img src="@source" />
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top