سؤال

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