Question

I have a Twitter Tweet button on the pages in my website. On the content pages, when you click the Tweet button, the link url is not getting added to the tweet.

Here's the code for the tweet:

<div class="col-xs-6 text-right">
    <a href="https://twitter.com/share" class="twitter-share-button text-right" data-lang="en" data-text="WrestleStat Eligibility Breakdown for @Model.Team.Name" data-url="http://www.wrestlestats.com/Team/EligibilityBreakdown?team=@Model.Team.Name.Replace("&", "%26")" data-size="60px" data-hashtags="WrestleStat #d1wrestle">Tweet</a>
</div>

The actual Tweet button works, so I don't think I need to add that code (request it if I still do).

This leads me to believe that it's a problem with the .Replace() on my @Model.Team.Name. The reason that was added was because a team called "Franklin & Marshall". That caused problems in urls since the & character was interpreted as a parameter instead of the actual text in the url.

Is that the issue with my tweet link url?

Was it helpful?

Solution

I went to the site you mentioned and found the page you're having issues with. If you go to a team without any spaces or special characters in it, the URL shows up when you attempt to tweet it. Seems like you need to URL encode the team names when they are displayed. It also could be easier to use an ID instead of a string of text with names so you don't have to URL encode them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top