Posts

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({ ...

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-p...

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);                 }                              }

Linq Query Syntax vs Method Syntax

Referenced from MSDN: https://msdn.microsoft.com/en-us/library/bb397947.aspx Query syntax: IEnumerable<int> numQuery1 =               from num in numbers             where num % 2 == 0             orderby num             select num; Method syntax:         IEnumerable<int> numQuery2 = numbers.Where(num => num % 2 == 0).OrderBy(n => n)

Sticky Footer made simple

CSS Footers are simple but people tend to overthink them.  Here is how it works You have two pieces A container that all your other stuff is in A footer that you want to always stay at the bottom of the page In Blazor I put this container on my content pages and not my host page because I didn't want my left hand nav to be involved <div class="container"> All my content </div> <footer> Centered footer content </footer> And the CSS .container {     width:100%;     padding: 0 15px; } footer {     font-size: 12px; (you could also use a vw value here)     padding-top:20px;     background-color: #xxx;     color: #fff;     margin: auto;     height: 60px;     width: 100%;     position: sticky; //absolute;     bottom: 0;     text-align: center; }

Ah Blazor - Now refresh the page!

Started my first Blazor project today.  New to NetCore as well so it was a fun challenge.  I like that is is similar to MVC  and I appreciate  the ability to add code into my page while building without moving to a controller - it was a real challenge to accommodate some JQuery but I got everything to work.  After looking a little closer I realized a large chunk of my JQuery and even javascript could be moved to the @code section and written differently - made for a cleaner, more readable page. I spent over an hour trying to figure out how to do a simple page refresh!  Part of the challenge is that Blazor is a moving target - different libraries and ways of doing simple tasks from version to version - I am confident that most of that will stop as they more clearly define what it is they want to do with this tool. Refresh a page (NetCore 3.1) First set up an alias for the uriHelper - you will now find it in NavigationManager @inject NavigationManager ...