Thursday, July 31, 2014

How can I check if one string contains another substring in JavaScript?

Ref:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf

Example:
var sample = "mytext";
console.log(sample.indexOf("my") > -1);
Output:
 true

Friday, July 25, 2014

Getting the left section of current Url upto domain name in C#

I was creating product's full links dynamically to do this I need to have the left section of the current URL from http to end of domain name.

Example:

My full link:
http://pro-post.blogspot.in/2014/07/extended-dropdownlistfor-to-create.html

I need: 
http://pro-post.blogspot.in

To achieve this ->

string leftSection = System.Web.HttpContext.Current.Request.Url.OriginalString.Replace(
System.Web.HttpContext.Current.Request.Url.PathAndQuery, "")
leftSection = leftSection.Substring(0, leftSection.LastIndexOf(':'));

ref: Soumyadip [http://soumyadip-cooldips.blogspot.in]

Wednesday, July 16, 2014

Extended DropdownListFor to create colored options

I had a situation to create a drop down list with multicolored options according to some criteria.
Like a dropdown consist of users, suppose users who are Administrator they will be shown in Green, if Restricted User then Red.
I have created this with DropDownListFor, by which it can be implemented easyly in mvc applications.

Steps:
1. Install Nuget package installer in visual studio.
2. Open Nuget Package Console
3. Write- Install-Package DropDownWithColorLegend