1- Forget the magic string
return View("Index");
or@Html.ActionLink("Delete Dinner", "Delete", "Dinners", new { id = Model.DinnerID }, null)
Nothing bad here, but nothing will tell you that to did a typo, or that the method name as changed. This is where T4MVC will become a great tool do add to all your project.
To add it a simple Nuget command is enough:
Install-Package T4MVC
. By doing this a T4 file (T4MVC.tt) will be added to your project that will generates a number of files. These generated files will simplify your life and gives you the opportunity to code using strongly type.Here are few transformations:
// Before ----------------
return View("Index");
// After with T4MVC
return View(Views.Index);
An action link in a view.// Before ----------------
@Html.ActionLink("Delete Product", "Delete", "Products", new { id = Model.ProductID }, null)
// After with T4MVC
@Html.ActionLink("Delete Product", MVC.Products.Delete(Model.ProductID))
An Ajax call.
// Before ----------------
<%= Ajax.ActionLink( "RSVP for this event",
"Register", "RSVP",
new { id=Model.DinnerID },
new AjaxOptions { UpdateTargetId="rsvpmsg", OnSuccess="AnimateRSVPMessage" }) %>
// After with T4MVC
<%= Ajax.ActionLink( "RSVP for this event",
MVC.RSVP.Register(Model.DinnerID),
new AjaxOptions { UpdateTargetId="rsvpmsg", OnSuccess="AnimateRSVPMessage" }) %>
A redirection.
// Before ----------------
return RedirectToAction("Details", new { id = product.ProductID });
// After with T4MVC
return RedirectToAction(MVC.Products.Details(product.ProductID));
When writing the code, it gives you intellisense where you normally would not have any. At compile time, it validates all the code so no typo or other misspelling errors are present.
2- Clean your views
So you can move the namespaces used globally
@using Microsoft.Security.Application
@using System.Globalization;
by including them to this section:
<system.web.webPages.razor>
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="Microsoft.Security.Application" />
<add namespace="System.Globalization" />
</namespaces>
</pages>
</system.web.webPages.razor>
3- Don't lose time debugging
Install it in ten seconds with the Nuget command manager and pick the version you need.
PM> Install-Package Glimpse
Glimpse is secure and is configured to be accessible only from localhost by default. But don't trust me and try it by yourself, or go check this one minute Glimpse Heads Up Display youtube video.
4- Start monitoring your website health and usage
To add it you got many possibilities, one of them from Visual Studio 2013, just right-click on the project and select Add Application Insights Telemetry, and voilĂ !
Now you just need to run or deploy the website and after few minutes or so you will have plenty of information, graphs waiting for you in the Azure Portal.
You will find a lot of information about Application Insights on the Microsoft Azure
Wrapping up
I hope it will help you, thanks for reading. Any comments, suggestions and/or questions are welcome.~ Frank Boucher
References
- T4MVC Documentation: https://t4mvc.codeplex.com/documentation
- Glimpse Documentation: http://getglimpse.com
- Application Insights: http://azure.microsoft.com/en-us/documentation/articles/app-insights-start-monitoring-app-health-usage/