Model binding Enum back to Object

Whe passing data from client (ko data back to MVC) where the object is an Enum of say 2 values. We need to either setup a Model Binder for that or take a shortcut ​as follows: <checkbox data-bind=”checked: viewModel.myStatus”> Enum MyStatus {Complete=1, NotStarted=0} And if myStatus is of type MyStatus then, we can say in ajax before […]

Long Running Task C#

Await and async in .NET 4.5 with C# public Task<string> RunSlowOperationTask()         {             return Task.Factory.StartNew<string>(RunSlowOperation);         } OR var taskData = new CalcTaskData {ForDate = forDate.Value, param2 = Value2};  Task t = new Task(() => DoCalcAsync(taskData));  t.Start(); // Long running Task private async Task DoCalcAsync(CalcTaskData calcTaskData) { // long operation // simulate long wait  (see note below) } Note that […]

Task.Run vs RunSynchronously

Task.Run = Tasks are executed asynchronously on a thread pool thread and do not block the calling thread. ​Task.RunSynchronously: Run on the calling thread, Blocks caller. Both cases need to Wait() to catch exceptions.. TaskScheduler: Latter: Task gets associated with the current TaskScheduler. If the target scheduler does not support running this task on the calling thread, the task will be […]

Export Table to Excel – Server side MVC

Excellent blogpost.. Using ClosedXml Nuget pkg.. ​http://www.c-sharpcorner.com/UploadFile/rahul4_saxena/export-data-table-to-excel-in-Asp-Net-mvc-4/​ Excerpt: public ActionResult ExportReportDataPerReport() DataTable dt = new DataTable(“ReportDataExport”); // tableName = ReportDataExport (also becomes sheet name in Xlsx) // Add Columns to the dt. Then add data using dt.NewRow and dt.AddRow … // Once dt is populated, run below code..             using (var wb = new XLWorkbook())   […]

NPM and Gulp

NPM is Node Package Manager and similar to Nuget. Uses package.json​ instead of package.config. Allows installation of Javascript based packages from the NPM website (npmjs.org). INSTALLING NODEJS and NPM: 1. Install Nodejs (x86 or x64 from the NodeJs.Org) — THIS makes your machine nodejs and npm enabled.. CHECK: Open command line and run node -v and npm -v. We should see […]

Angular 2 First Look

Pluralsight course – Angular 2 First Look (John Papa)  https://app.pluralsight.com/library/courses/angular-2-first-look/table-of-contents Ready to use / run samples: (edit/run in Plunker online) http://a2-first-look.azurewebsites.net/ (or http://jpapa.me/a2firstlook) Further reference n quickstarts: https://angular.io/docs/ts/latest/guide/ https://angular.io/docs/ts/latest/guide/architecture.html

Debug Error 500 – IIS

1. ​Howto force error 500 to enable testing the error output and logging: Navigate to site root or a page with ?someParam=<script> (note: this will be treated a a dangerour script and error 500 thrown). 2. MVC Web.config <httpErrors errorMode=”Custom” existingResponse=”Auto”>       <remove statusCode=”404″ />       <error statusCode=”404″ path=”/404.html” responseMode=”ExecuteURL” /> […]

Browsers Reference

Microsoft Edge Platform Status: https://dev.windows.com/en-us/microsoft-edge/platform/status/xmlhttprequesttimeout​ Feature wise lookup:​ http://caniuse.com/  (e.g. http://caniuse.com/#search=border-radius) ​ http://caniuse.com/#comparison

Shim Shiv Polyfill

Shim=Shiv (latest http://cdnjs.com/libraries/html5shiv) Kind of like polyfills cover over the differences in implementations of features. The way the HTML5 shiv works requires you to put it in the <head> element Also refer to excellent reference on Html5 polyfilling https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-Browser-Polyfills​​