Skip to main content

Posts

Showing posts from June, 2014

Generic method to convert enum datatype to select list item

// Generic method to convert enum datatype to select list items public static List < SelectListItem > GetEnumSelectListItems<T>() {     List < SelectListItem > list = new List < SelectListItem >();     foreach (T type in Enum .GetValues( typeof (T)))     {         list.Add ( new SelectListItem ()  {              Selected = false ,             Text = type.ToString(),             Value = type.ToString()         } );     }     return list; }

open a url in a new window in html javascript

function OpenPopUpWindow(url) { params = 'width=' + Math.round(screen.width * .90); params += ', height=' + screen.height; params += ', top=0, left=' + Math.round(screen.width * .05); params += ', fullscreen=no' ; params += ', scrollbars=yes' ; var newwin = window.open(url, 'windowname' , params); if (window.focus) { newwin.focus() } if ( typeof this .stopPropagation != 'undefined' ) { this .stopPropagation(); } return false ; }

ajax post request

$.ajax({   url: url,   type: "POST" ,   contentType: 'application/json' ,   data: JSON.stringify($scope.Model) }) .done(successCallback) .fail(failureCallback); function successCallback(){    // on success } function failureCallback(){    // on failure }

Creating angular scope base with angular bootstrap (my custom base model)

<div id="myArea" ng-controller="myController"> </div> <script type="text/javascript">     angular.bootstrap(document.getElementById("myArea"), ["myController"]); </script> var my = angular.module('my', []); var myScope = null; function myController($scope, $timeout) {     // Enable global access of this scope .     if (myScope == null)         myrScope = $scope; if (typeof _myModel != 'undefined' && _myModel && _myModel != "") {         $scope.Model = angular.extend($scope.Model, _myModel);     } }