Posts

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

From Checkbox to Linq list

Just the Values of the Selected Items List <string> selectedValues = chkMyList . Items . Cast < ListItem >() . Where ( li => li . Selected ) . Select ( li => li . Value ) . ToList (); Both Text and Value of Selected item into a listItem object List < ListItem > selected = chkMyList . Items . Cast < ListItem >() . Where ( li => li . Selected ) . ToList ();

Linq Compare to a list

Establish your list var idList = new [] {5, 7}; Compare against the List var jobs = originaljobs.Where(t => t.StatusId != null).Where(t => idList .Contains((int)t.StatusId));  

Conversion Classes

Convert from Model to Dataset public static DataSet ToDataSet (this IList list) { Type elementType = typeof(T); DataSet ds = new DataSet(); DataTable t = new DataTable(); ds.Tables.Add(t); //add a column to table for each public property on T foreach (var propInfo in elementType.GetProperties()) { Type ColType = Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType; t.Columns.Add(propInfo.Name, ColType); } //go through each property on T and add each value to the table foreach (T item in list) { DataRow row = t.NewRow(); foreach (var propInfo in elementType.GetProperties()) { row[propInfo.Name] = propInfo.GetValue(item, null) ?? DBNull.Value; } t.Rows.Add(row); ...