Question

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?

Was it helpful?

Solution 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")' + 
        '" />';
}

OTHER TIPS

There is a problem in the src. Check the url

It might be

 src="/Content/Images/greenDot.gif"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top