Sunday, December 25, 2016

c# find number of occurance of substring in string

Regex.Matches(inputstring, substring).Count

Monday, December 12, 2016

.net mvc code first database migration configuration seed method error debugging

add the following code into the constructor of the method Configuration:

if (System.Diagnostics.Debugger.IsAttached == false)
            {
               System.Diagnostics.Debugger.Launch();
            }

Tuesday, January 12, 2016

mvc 5 bootstrap datetimepicker incorrect display

when setup datetime display format in javascript it displays datetime value incorrectly, the following are what I have done to ensure my datetime value is displayed correctly

in my javascript I have



$('.dtpicker').datetimepicker({
        format: 'YYYY/MM/DD HH:mm'
    });


in my model I have a property 



[Display(Name = "Paid Time")]
 [DisplayFormat(DataFormatString = "{0:yyyy/MM/dd HH:mm}")]
public DateTime PaidDateTimeLocal { get; set; }


in my view I make sure the datetime format is reinforced

@Html.TextBoxFor(model => model.PaidDateTimeLocal, new { Value = Model.PaidDateTimeLocal.ToString("yyyy/MM/dd HH:mm"), @class = "dtpicker" })