Showing posts with label attribute. Show all posts
Showing posts with label attribute. Show all posts

Tuesday, June 6, 2017

Jquery attr method


Issue

I had a checkbox with imbedded attributes.  I needed to get these values out of based on a click event
The key to getting the specified values was the use of the attr method.

<input name="SavePaySchedule" id="SavePaySchedule1" type="checkbox" value="true" selectedscheduleitem="1f3dc523-c466-4dc5-bb52-09848a79c9fd" schedulecountry="44207e0b-d4ca-4bfd-b1b3-2f28a2c6d5ef">


 <script type="text/javascript">
                                    $('#SavePaySchedule').click(function (o) {
                                        var $input = $(this);
                                        var scheduleCountry = $input.attr('scheduleCountry');
                                        var selectedScheduleItem = $input.attr('selectedScheduleItem');
                                        var activeState = $input.prop('checked');

                                    });
                                </script>

Source

http://api.jquery.com/attr/

Wednesday, March 22, 2017

MVC attribute DataFormatString

Issue

Needed to format dates in an MVC model.  I wanted to use the attribute decorators for the properties.
I just could not remember the syntax for DataFormatString

  [Display(Name = "Date Notified")]
  [DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy} ")]
  public DateTime? Received_Date { get; set; }

{0:dd MMMM yyyy}    -    gives 24 February 2006
{0:MMM dd}    -    gives Feb 24 (substitue MMM with MMMM for the full month name instead of abbreviation)
{0:dd/MM/yy}    -    gives 24/02/06
{0:dd/MM/yyyy}    -    gives 24/02/2006


Source

https://social.msdn.microsoft.com/Forums/windows/en-US/bb8b1e0e-bd41-4206-9895-4e79463b9bc6/dataformatstring-for-datetime-column?forum=winformsdatacontrols