I have a mvc view which needs to show the twitter feeds. So i have the code generated from twitter in my view. This works fine.
To extend this i want to make this a little dynamic. ie i want to hardcoded data-widget-id="3831079557xxxx" to a value from a database table.
Below is the javascript generated by twitter to embed the tweets
<div class="row">
<div class="col-md-12">
<a class="twitter-timeline" href="https://twitter.com/xxxxx"
data-widget-id="3831079557xxxx">Tweets by xxxx</a>
<script>!function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https'; if (!d.getElementById(id)) { js = d.createElement(s); js.id = id; js.src = p + "://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); } }(document, "script", "twitter-wjs");</script>
</div>
</div>
View Model:
public class homeViewModel
{
public List<news> newsA { get; set; }
public List<Rss> feeds { get; set; }
public List<HomepageSetting> hps { get; set; }
}
Model: This is the class from which i can get the twitter id
public partial class HomepageSetting
{
public int Id { get; set; }
//other properties
public string Twitter { get; set; }
}
Controller:
public ActionResult Index()
{
homeViewModel hvm = new homeViewModel();
var data = (from p in db.HomepageSetting where p.ProfileID == Cuser.ProfileId select p);
hvm.hps= data.ToList();
return View(hvm);
}