C#
public ActionResult GetBanners()
{
List<BannerImage> bannerImages = new List<BannerImage>();
bannerImages.add(new BannerImage(){Id = 1, TargetUrl = "http://www.google.com", ImageUrl= 'Image1'});
bannerImages.add(new BannerImage(){Id = 2, TargetUrl = "http://www.yahoo.com", ImageUrl= 'Image2'});
bannerImages.add(new BannerImage(){Id = 3, TargetUrl = "http://www.msn.com", ImageUrl= 'Image3'});
return view(bannerImages);
}
查看(.cshtml)
@model IEnumerable<MyApp.Areas.Admin.ViewModel.BannerImage>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table table-bordered table-striped" >
@foreach (var item in Model) {
<tr>
<td>
<a onclick="ClickMethod()" href = "@item.TargetUrl"> <img src = "@item.ImageUrl" /> </a>
</td>
</tr>
}
</table>
我正在我的应用程序中显示外部网站的横幅广告。在这里,我面临如何跟踪的挑战:
1.视图
2.展示次数(意味着广告在屏幕范围内对用户可见)
3.今天的印象
4.点击今天
我的方法
public ActionResult GetBanners()
{
// before showing the ads, I am inserting the ads for view in Userads database table
Updatebannerviews();
}
public ActionResult ClickMethod()
{
// I am inserting the ads for clicks in Userads database table
UpdateBannerClicks();
return json("Success", JsonBehavior.AllowGet);
}
public ActionResult Impressions()
{
// I am inserting the ads for impressions, in Userads database table
UpdateBannerImpressions();
return json("Success", JsonBehavior.AllowGet);
}
这是正确的方法吗?或者,还有更好的方法?请指教。预先感谢。