How to pass values from ASP.NET MVC Razor Views to Angular Controller ?

I have been using a lot of AngularJs code on my razor views lately. On one of my page, I wanted to pass to my angular controller the model which is being passed to my razor view.

Can be done with the following code


JsonConvert.SerializeObject helps you convert an object to a JSON string and you can use ng-init to pass and use this value in your controller.

How to configure the default ASP.NET Membership’s Role Manager in ASP.NET MVC 4

If you do not want to create your own custom Role Provider and use the ASP.NET Membership’s in built RoleManager. Then you should use the following setting in your web.config file.

<roleManager enabled="true" defaultProvider="SqlRoleProvider" >
    <add name="SqlRoleProvider"
         applicationName="Abc Web Application"/>

Font awesome not working on IIS for ASP.NET MVC project

Here are things that you should be checking if your fontawesome is not working when you put your website on IIS.

enter image description here

Check 1: Check if all the fonts (.otf, .woff etc) are copied to the /font-awesome-4.2.0/fonts/ folder.

Check 2: Remove the fontawesome.css from your bundle and add it directly like <link href="~/Content/font-awesome-4.2.0/css/font-awesome.css" rel='stylesheet' type='text/css' />

Setting up Staging, QA and Live web configs with Visual Studio 2013

Step 1 : Open the Configuration Manager dialog.
enter image description here

Step 2 : Select “<New..”> option from the Active solution configuration dropdown.
enter image description here

Step 3: Give some name to your configuration, and if you dont require an empty config file I would suggest you to copy the settings from the existing “Release” transform.
enter image description here

Step 4: Right click on the web.config file and select the “Add Config Transform” option.
enter image description here

Step 5: And you should see your Staging config created. You can similarly create a qa and production/live configs too.
enter image description here

How to conditionally add remove required attribute in Angular Js ?

Working on a form and its validation using AngularJs, I was using the “required” attribute to mark fields required. However there were few fields that should be required depending on input on other fields. This seemed little tricky at first, I also posted this as a question on SO.

Here is what I ended up using:

<input type="text" value="" 
  ng-required="addressRequired" />

Simple and clean :)

How to stop SignalR from polling when using Visual Studio 2013 ?

I recently moved to Visual Studio 2013. One thing that I noticed when console debugging was that there were tooooo many “GET”/”POST” request being made. These requests were not being made by any of my written code.

enter image description here

On checking this closely, I found these calls were made to /arterySignalR/poll?transport=longPolling..... Artery aka BrowserLink is a real-time connection from Visual Studio to all browsers running your code. It essentially allows Visual Studio to interact with every browser.

Here’s how to stop this: Uncheck Enable browser link.

enter image description here

How To Use Entity Framework With MySql Database ?

Step 1 : Download and Install

First, you will need to download and install the following

Step 2 : Create A Database To Connect To

Make sure you create a database and a table with few columns for testing the connectivity using EF. In my example I have a ‘UserProfile’ table which has fields like userId, email, firstName, lastName etc.

Step 3 : Add Reference To Your Project

Add MySql.Data.dll and MySql.Data.Entity.dll to your project. enter image description here

Step 4 : Add ADO.NET Data Entity Model

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Step 5 : Time To Test

public User CreateUser(User model)
    using (var context = new TestMySqlDbEntities())
        // add user
        var createdUser = context.Users.Add(model);

    return model;

Show time spent in years, days, minutes and seconds using Moment.js

For the homepage of this blog, I wanted to show a timer which shows the number of years/days/minutes & seconds spent since I started working. This blog post is tutorial on how to do that.

Firstly you will need to download and include moment.js. Here is a fiddle you can play around which and below is the code for your refrence.


<div>Time spent making websites</div>
<div id="timer">


$(document).ready(function () {
    // this function is only used so that I can use the .format() function in this example.
    if (!String.prototype.format) {
        String.prototype.format = function () {
            var args = arguments;
            return this.replace(/{(\d+)}/g, function (match, number) {
                return typeof args[number] != 'undefined' ? args[number] : match;

    window.setInterval(function () {
    }, 1000);


function refreshTimer() {
    var now = moment();
    var start = moment([2010, 12, 22]);
    var years = now.diff(start, 'years');
    var days = now.diff(start, 'days');
    var hours = now.diff(start, 'hours');
    var minutes = now.diff(start, 'minutes');
    var seconds = now.diff(start, 'seconds');
    $("#timer").html("<span id='years'>{0} years</span><span id='days'>{1} days</span><span id='hours'>{2} hours</span><span id='minutes'>{3} minutes</span><span id='seconds'>{4} seconds</span>".format(years, days, hours, minutes, seconds));


#timer span {margin-right:10px;}