How to get Query Params in Web API ASP.Net C# from Request

Since ApiController was made to work without IIS Hosting, it does not depend upon the HttpContext object. We need System.Net.Http namespace to get the extension method GetQueryNameValuePairs() Request.GetQueryNameValuePairs() To get the param values from the query string, we need another namespace System.Linq URL: http://localhost/Person?query=test Request.GetQueryNameValuePairs().Where(nv => nv.Key == “query”).Select(nv => nv.Value).FirstOrDefault()

Continue reading


Get Slug of string using c#

public static string ToSlug(string value) { //First to lower case value = value.ToLowerInvariant(); //Remove all accents var bytes = Encoding.GetEncoding(“Cyrillic”).GetBytes(value); value = Encoding.ASCII.GetString(bytes); //Replace spaces value = Regex.Replace(value, @”\s”, “-“, RegexOptions.Compiled); //Remove invalid chars value = Regex.Replace(value, @”[^\w\s\p{Pd}]”, “”, RegexOptions.Compiled); //Trim dashes from end value = value.Trim(‘-‘, ‘_’); //Replace double occurences of – or \_ […]

Continue reading


How to create jQuery datatables grid with ASP.NET MVC

http://www.codeproject.com/Articles/155422/jQuery-DataTables-and-ASP-NET-MVC-Integration-Part http://www.codeproject.com/KB/aspnet/MVC-CRUD-DataTable.aspx http://www.codeproject.com/KB/aspnet/Parent-Child-DataTables.aspx http://www.codeproject.com/KB/aspnet/Expandabe-DataTable-MVC.aspx http://www.codeproject.com/Articles/331855/jQuery-DataTables-Advanced-Filtering-in-ASP-NET-MV http://www.codeproject.com/Articles/331986/Table-Row-Drag-and-Drop-in-ASP-NET-MVC-JQuery-Data http://www.codeproject.com/Articles/scripting/JQuery-DataTables.aspx

Continue reading


How to create multiple dbcontext in entity framework

Creating Multiple DbContext in EntityFramework Is it possible to have multiple dbcontext? Yes, we can create multiple DbContext classes in EF, which you can see below. Syntax: Enable-Migrations -ContextTypeName<DbContext-Name-with-Namespaces> -MigrationsDirectory:<Migrations-Directory-Name> Add-Migration -configuration <DbContext-Migrations-Configuration-Class-with-Namespaces> <Migrations-Name> Update-Database -configuration <DbContext-Migrations-Configuration-Class-with-Namespaces> -Verbose Sample: Enable-migrations -ContextTypeName Migrations.DbContexts.Configuration -MigrationsDirectory:DbContexts Add-Migration -configuration Migrations.DbContexts.Configuration Update-Database -configuration Migrations.DbContexts.Configuration -Verbose

Continue reading


How to create custom extensions in asp.net mvc

Custom Extension in ASP.NET MVC 1. Create a folder named Utilities inside project folder. 2. Create your extension class as static class. namespace AlobinProject.Utilities { public static class Utilities { public static string HelloWorld(this HtmlHelper html) { return “Hello World”; } } } 3. Create a static method inside the extension class. 4. Declare the […]

Continue reading