Posts

Showing posts from 2021

Linq list filtered on list

modelItems is a list of Model intList  is a list of Integers I am looking for modelItems where the id is in my Int List var myFilteredList= modelItems.Where(item => intList.Contains(item.Id))   .Select(a => a).ToList();

Dynamic Dropdowns NetCore and Json

 Html for placeholder   <select id="AppList"  class="form-control input-sm"></select> Controller returns  a Model - Add records to the Model and then return as JsonResult  public async Task<JsonResult> GetApplications(int id) {           var selectAppList = new List<ModelName>();              var apps =  _applicationService.GetApplicationModels();                 var modelVariable = (await GetModelRecords);  if (modelVariable is object ) {                   selectAppList.Add(modelVariable); }       return Json(selectAppList);  } Jquery Add something like this to document.ready $("#brandId").change(function () { var id = $("#brandId").val(); BuildAppList(id); }); Then add the function function BuildAppList(id) { $.ajax({ type: 'GET', url:'ConfigureKey/GetApplications/' + id, data: { id: id }, success: function (result) { $('#AppList').empty(); $.each(result, function (i,

Ajax Loop Photos

function GetPhotos() {     var row = "<div class='w3-container w3-row-padding'>";     var itemcount = 0;     $.ajax({         url: '/Photos/PhotoList',         type: 'GET',         contentType: 'application/json',         data: "{}",         dataType: "json",         success: function (data) {             var count = Object.keys(data).length;            // var row = "";                          $.each(data, function (item) {                                              if (itemcount % 6 != 0) {                     row += "<div class='w3-left w3-padding-16'><div class='w3-container w3-center' style='width: 150px;'><img class='w3-round-xlarge' alt='"+ itemcount +"' onclick=" + "if(event.shiftKey){document.getElementById('dispImage')" + ".src='" + data[item].photoSrc + "';" + "document.ge

MVC Changed State with no query string

 I needed to take action if i was in the edit state of my page.  So in the controller I set a ViewBag object then from my jquery I checked the value I needed to check a NO value in a checkbox if there was no textarea value in the model set  var number = parseInt(@ ViewBag.Edit );             if (number == 1) {                 if ($("#TextAreaEngagement").val().length == 0) {                     $("#chkEngagedNo").prop("checked", true);                 }                              }