문제

I am using mvc4, Razor and SignalR. Now in my cshtml. i have

<div>
<ul id="friends"></ul>
</div>

and within the script i have

$(function () {

//code omitted

// Reference the auto-generated proxy for the hub.
var chat = $.connection.chatHub;

chat.client.addfriend = function (name) {
// Add the message to the page.
$('#friends').append('<li><strong>' + htmlEncode(name)
+ '</strong> ' + getOnlineIcon() + '</li>');
};

function getOnlineIcon() {
return '<img id="img_logo" alt="test" src="~/Content/Images/greenDot.gif" />';
}
}

Issue is i tried everything, but it never shows the image only the alt text. If i put the same tag within the outside the script it works fine meaning the path is okay. Just that within the script it has an issue. tried the url.content on the src as well, but no luck. Any suggestions?

도움이 되었습니까?

해결책 2

try using

@Url.Content("~/Content/Images/greenDot.gif")


like this..

function getOnlineIcon()
{
    return '<img id="img_logo" alt="test" src="' + 
        '@Url.Content("~/Content/Images/greenDot.gif")' + 
        '" />';
}

다른 팁

There is a problem in the src. Check the url

It might be

 src="/Content/Images/greenDot.gif"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top