Thursday, June 8, 2017

MVC Caching issue

Issue:

I had an issue with a MVC view rendering a modal page.  The problem was that the AJAX call was not refreshing the view when it was re-rendered on the page.  The change to the database is occurring but the view refresh was not showing the latest information.

 var data = { "claimNumber": activeClaimID };
        $.ajax
        (
                 {
                     url: '@Url.Action("IndexPartial", "CaseFileViewModels")',
                     async: false,
                     type: 'GET',
                     data: data,
                     success: function (result) {

                         hideWaitDialog();
                       
                         //Clear out the entire modal block
                         $('#modal-container').empty();
                         $('#modal-container').append(result);
                         ret = true;
                     },
                     error: function (xhr, status, err) {
                         alert(xhr.responseText);
                         alert(status);
                     },
                 }
         );


My problem was that I did not assign the attribute Output Cache to the ActionResult.
Once I disabled the default hander on ActionResult then my view began to refresh.

[OutputCache(Location = System.Web.UI.OutputCacheLocation.None)]
public ActionResult IndexPartial()
{....}


Source:

https://stackoverflow.com/questions/20917398/view-not-refreshing-after-ajax-call


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/

Linq to SQL distinct

Issue:

I needed to get a distinct value from a query like

select distinct o.ProgramID,t.Program
from table1 o
inner join table2 t on o.ProgramID=t.ProgramID
order by t.Program

var result = (from o in table1
              join t in table2 on o.ProgramID equals t.ProgramID
              orderby t.Program
              select new { o.ProgramID, t.Program }).Distinct();
https://stackoverflow.com/questions/4318909/linq-to-sql-distinct-and-orderby