ASP.NET MVC with google analytics tacking root url - asp.net-mvc

I have an ASP.NET MVC site and my google analytics code is the example code cut/pasted into my layout page. This is how it records root requests:
Can anyone tell me how to get it to record only the / as the root url? For reference here is my analytics code:
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("my code");
pageTracker._trackPageview();
} catch (err) { }
</script>

You need to set the _trackPageview value to the page you want to log the metrics under, e.g.:
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("my code");
pageTracker._trackPageview("/");
} catch (err) { }
</script>

Related

TFS Code Coverage on startup screen?

In TFS it is possible to get build historical data on start screen. So when you log into TFS you immediately see the status of your builds. Can the same be achieved for displaying Code Coverage? This is something that SonarCube definitely does nicely.
There isn’t the feature of include Code Coverage result in start screen. But you can custom dashboard widget with test REST API to achieve that.
A simple sample to custom dashboard:
<!DOCTYPE html>
<html>
<head>
<title>Custom widget</title>
<meta charset="utf-8" />
<script src="node_modules/vss-web-extension-sdk/lib/VSS.SDK.js"></script>
<script type="text/javascript">
VSS.init({
explicitNotifyLoaded: true,
usePlatformStyles:true
});
VSS.require(["TFS/Dashboards/WidgetHelpers","TFS/TestManagement/RestClient"], function (WidgetHelpers,TFS_Test_WebApi) {
WidgetHelpers.IncludeWidgetStyles();
VSS.register("WidgetStarain", function () {
var projectId = VSS.getWebContext().project.id;
var getCodeCoverage = function (widgetSettings) {
return TFS_Test_WebApi.getClient().getBuildCodeCoverage(projectId, 252)
.then(function (buildCoverage) {
var $codeCoverageResult = $('div.codeCoverage');
var $codeCoverageObject = buildCoverage.coverageData[0].coverageStats;
var $detailResult = $codeCoverageObject[0].label + ": Total:" + $codeCoverageObject[0].total + ";covered:" + $codeCoverageObject[0].covered;
$codeCoverageResult.text($detailResult);
//$codeCoverageResult.text(JSON.stringify(buildCoverage))
return WidgetHelpers.WidgetStatusHelper.Success();
}, function (error) {
return WidgetHelpers.WidgetStatusHelper.Failure(error.message);
});
}
return {
load: function (widgetSettings) {
var $title = $('h2.title');
$title.text('starain widget custom');
return getCodeCoverage(widgetSettings);
}
}
//return {
// load: function (widgetSettings) {
// var $title = $('h2.title');
// $title.text('starain widget custom');
// return WidgetHelpers.WidgetStatusHelper.Success();
// }
//}
});
VSS.notifyLoadSucceeded();
});
</script>
</head>
<body>
<div class="widget">
<h2 class="title">widgets starain</h2>
<div class="codeCoverage">non code coverage</div>
</div>
</body>
</html>
After that, you can add that widget to the dashboard and check code coverage.

Query is not defined error jquery-ui.min.js

I am getting a Chrome console jQuery is not defined error for jquery-ui.min.js
In my site I put jquery call at bottom:
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js" type="text/javascript"></script>
<!--JScript to Make iframe go behind footer nav upon scrolling in IE -->
<script type="text/javascript">
var $j = jQuery.noConflict();
jQuery(document).ready(function($j){
$j('iframe').each(function() {
var url = $j(this).attr("src");
if ($j(this).attr("src").indexOf("?") > 0) {
$j(this).attr({
"src" : url + "&wmode=transparent",
"wmode" : "Opaque"
});
}
else {
$j(this).attr({
"src" : url + "?wmode=transparent",
"wmode" : "Opaque"
});
}
});
});
</script>
The page is this: http://www.mexpro.com/mexico/auto/insurance.html
jQuery-UI is only a plugin for jQuery. You need to add this instead.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>

Autocomplete not working in asp.net mvc

I am trying to create a textbox that autocomplete when a user start do search for some name, but it's not working.
Here is my view:
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/cupertino/jquery-ui.css" type="text/css" rel="Stylesheet" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#txtSearch").autocomplete({
source: '#Url.Action("pesquisarUsuario")',
minLength: 0
});
});
</script>
<h2>Index</h2>
#using (#Html.BeginForm())
{
#Html.TextBox("pesquisa", null, new { id = "txtPesq" })
<input type="submit" value="Pesquisar" />
}
And here is my controller:
public JsonResult pesquisarUsuario(string term)
{
List<string> usuario;
usuario = db.usuario.Where(u => u.nomecompleto.StartsWith(term))
.Select(u => u.nomecompleto).ToList();
return Json(usuario, JsonRequestBehavior.AllowGet);
}
Am I missing something? because my textbox does not show any users when I start do write.
First try if usuario returns anything. :-)
Try in your browser: http://localhost:port/yourcontroller/pesquisarUsuario?term=t
It should return all records starting with 't'.
If it does not return anything, here is your problem.
If it does, try to set the full url:
$(document).ready(function () {
$("#txtSearch").autocomplete({
source: 'http://yourserver/yourcontroller/pesquisarUsuario',
minLength: 0
});
});
EDIT:
I have created this tutorial with a fully working example: http://r2d2.cc/2014/09/11/autocomplete-jquery-ui-with-asp-net-mvc-simple-example/

showing a view as popup in mvc4 pattern

I've a view rendered with Razor engine and I need to open at a button click a popup to insert a new user (i've already got my view/controller for the InsertUser)
I wish to know what the correct workflow to perform this, if I open it with jQuery how do I tell after the insert to close the view? my controller doesn't know it's on a popup and I've not seen any CloseResult as ActionResult... I'm using also KendoUI, I've seen it has the Window control....this as well won't help me on this.....what's best to use for opening a popup?
Thanks
Try reading this article on progressive enhancement, while you might not want to do it progressivly the article contains all the little recipes you will need to do it.
Your get action would be like this:
[HttpGet]
public ActionResult ContactUs()
{
return PartialView("_ContactUs");
}
Your post like this:
[HttpPost]
public ActionResult ContactUs(ContactUsInput input)
{
if (!ModelState.IsValid)
{
return PartialView("_ContactUs", input);
}
return PartialView("_ThanksForFeedback", input);
}
The front end something like this:
<script src="#Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery-ui.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="#Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
<script type="text/javascript">
$.ajaxSetup({ cache: false });
$(document).ready(function () {
$(".openDialog").live("click", function (e) {
e.preventDefault();
$("<div></div>")
.addClass("dialog")
.attr("id", $(this).attr("data-dialog-id"))
.appendTo("body")
.dialog({
title: $(this).attr("data-dialog-title"),
close: function () { $(this).remove() },
modal: true
})
.load(this.href);
});
$(".close").live("click", function (e) {
e.preventDefault();
$(this).closest(".dialog").dialog("close");
});
});
</script>
<a class="openDialog" data-dialog-id="emailDialog"
data-dialog-title="Contact Us" href="/Home/ContactUs">Contact Us</a>

hiding actions menu in sharepoint list

i am using the following code to hide the Actions menu from Discussion Board list. The code is :
<script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.3.2.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$('.ms-menutoolbar td:lt(4)').hide();
});
</script>
I found this from an article, but its not working. Can you please help me regarding hiding Actions menu from Discussion Board list.
Also tried this code with no luck:
<script>
function HideDiv(name) {
var div = document.getElementsByTagName('div');
for (var i = 0; i < div.length; i++) {
var str = div[i].id;
if (str.indexOf(name) >= 0) {
var viewInExplorer = div[i];
if (viewInExplorer != null) {
if (viewInExplorer.parentNode != null)
viewInExplorer.parentNode.removeChild(viewInExplorer);
}
}
}
}
HideDiv("ListActionsMenu");
</script>
You might want to think about using a Custom Action to hide the menu items:
See:
http://msdn.microsoft.com/en-us/library/ms414790.aspx
and
http://msdn.microsoft.com/en-us/library/ms465980.aspx
You can use the below script but i would suggest to use custom master page in which you just remove site action or apply a sharepoint security trim control so that it is visible to administrator only
<script type="text/javascript" > this.document.getElementById("siteactiontd").style.display = 'none'; </script>
<script src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.3.2.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$('.ms-menutoolbar td:eq(2)').hide();
$('.ms-menutoolbar td:eq(3)').hide();
});
</script>
Without using JavaScript you can do this less complicated. Just find element <td> with id="siteactiontd" in masterpage and set style style="visibility:hidden" (using SharePoint Designer) like so:

Resources