Posts

Load MVC view to jquery color box

  You can use the following set of code to load a MVC view to a jquery color box. You can get more details on jquery colobox here . HTML code < table cellpadding ="0" cellspacing ="0" border ="0" class ="display" id ="ClientConfigurationList" style =" width : 100%" >          < thead >              < tr >                                                < th > Work Order No </ th >                  < th > Work Order Status </ th >                  < th > Created On </ th >                  < th > Completed On </ th >                  < th > Asset Description </ th >              </ tr >          </ thead >          < tbody >              @ foreach ( var item in Model)              {                  < tr class ="leftAlign">                                                         ...

Dynamically Load External JS , CSS file paths in webconfig

  If you want to load JavaScript paths or CSS paths saved in web config app settings you can use the following solution. Step 1: Create a API controller method which will return the appsettings public class ConfigurationController : ApiController   {          [ HttpGet ]        public string LoadSettings(Domain.Entities. Configuration model)   {       string value = ConfigurationManager .AppSettings.Get(model.Key);       return value;   }   }   Step 2: Create a javascript function which will load javascript or css paths dynamically. function loadjscssfile(filename, filetype) {        if (filetype == "js" ) { //if filename is a external JavaScript file            var fileref = document.createElement( 'script' );            fileref.setAttribute( "type" , "text/javascript" );            fileref.setAttribute( "src" , filename);        }        else if (filetype == "css" ) { //...

Validating Username, password and timestamp in WCF

  Recently I have got an requirement which is to validate username, password and timestamp set in the message header in each call made to WCF. Following is the solution I came Up with.   Validating Username and Password   Step 1: Create a wshttpbinding and add the following configuration. < wsHttpBinding >      < binding name = " wsHttpBinding " closeTimeout = " 00:00:10 " openTimeout = " 00:00:10 " receiveTimeout = " 00:00:10 " sendTimeout = " 00:00:10 " >        < security mode = " Message " >          < message clientCredentialType = " UserName " />        </ security >      </ binding >    </ wsHttpBinding >   Step 2: Create a custom username and password validator as below public class UserValidator : UserNamePasswordValidator    {        public override void Validate( string userName, string password) ...

OData in WebApi 2

  Web API 2 comes with OData query support. It supports the following query options for webAPI client applications to customize the result set returned by the API based on there requirement. Option Description $expand Expands related entities inline. $value Gets the raw value of a property. $filter Filters the results, based on a Boolean condition. $inlinecount Tells the server to include the total count of matching entities in the response. (Useful for server-side paging.) $orderby Sorts the results. $select Selects which properties to include in the response. $skip Skips the first n results. $top Returns only the first n the results.   To use OData queries you need to enable it globally, controller or specific action level. Enable Globally 1. In you MVC project go to App_Start folder 2. There you can find the WebApiConfig.Cs 3. In there add the following code. public static void Register( HttpConfiguration config)     {         ...

Enum Support in MVC 5.1

Image
  Enum support for MVC views is a new feature introduced in Asp.net MVC 5.1. If you have Enum in your model view will create a dropdown list or radio button list in the view for you. See the example below. Model public class MyData      {          public int Id { get ; set ; }            public MyEnum Enum1 { get ; set ; }            public MyEnum ? Enum2 { get ; set ; }            public FlagsEnum FlagsEnum { get ; set ; }      }   Enum as Dropdown List   < div class ="form-group">           @Html.LabelFor(model => model.Enum1, new { @class = "control-label col-md-2" })           < div class ="col-md-10">               @Html.EditorFor(model => model.Enum1)               @Html.ValidationMessageFor(model => model.Enum1)           </ div >       </ div >         < div class ="form-group">           @Html.LabelFor(model =>...

TestCase Attribute (NUnit 2.5)

Image
Have you ever thought how easy would it be if we could pass parameters and expected result to a Unit Test method we have rather writing multiple test methods. It is possible now with NUnit 2.5 “ TestCase ” Attribute. Suppose you have a method to test whether a year is a leap year or not which you want to test by passing different values here is the solution. [TestCase(2000, Result = true)] [TestCase(1996, Result = true)] [TestCase(2013, Result = false)] public bool IsLeapYearTest(int year) { return DateTime.IsLeapYear(year); } and if you want to pass multiple parameters just add them comma seperated as below example. [TestCase(12, 3, Result = 4)] [TestCase(12, 2, Result = 6)] [TestCase(12, 4, Result = 3)] public int DivideTest(int n, int d) { return (n / d); } This helps us to provide test methods with parameters as well as providing inline date to be ...

February 2014

  Please find the presentation & the sample code for February Sri Lanka .net Forum meet up which I did on c# interfaces here. https://skydrive.live.com/redir?resid=80EDE0125C9CA03A!109&authkey=!AJKHEV7BrDCEP1c&ithint=file%2c.zip