ASP.NET MVC: Display Total and Avg in Table footer in Razor Views

There are various cases in which you may want to display results from aggregate functions (Sum, Avg, Count, Min, Max) performed over the columns in the grid in their footer. This post explains how to display aggregate functions in ASP.NET MVC Razor views.

Used Environment for this post: VS 2015 Update 3, ASP.NET MVC 5

For ASP.NET Web Forms, Read following post:
Displaying Total in ASP.NET Gridview Footer Row Without using Template Field

Azure Functions + Cognitive Services: Automate Image Moderation

Generally, User submitted images (profile pictures, social media posts, and business documents) are needed to be moderated to protect business and quality. If a large number of images are submitted in an application then manual moderation is time consuming and is not instantaneous. This post explains how to automate image moderation using Azure functions and Cognitive Services. Automated moderation applies machine learning and AI to cost-effectively moderate at scale, without human involvement.

Generalize a method to read any master table with C# and Dapper

On a web page or application form, it is common to have different master data like Country, State…etc. available in dropdownlist, listbox or any other control. It is needed to read all master data from database and bind to proper controls. This post explains different ways to read master tables with C# and Dapper.

PostgreSQL Enum, C# and Dapper

Error: column "Gender" is of type enum but expression is of type text.

Are you getting this error when you are using enum datatype in PostgreSQL database? This blog post explains how to fix the error with C# and Dapper. The following environment is used for this post:

Export Data to Excel (.xls, .xlsx) in ASP.NET – C#

In this article, we will see different ways to export data to Excel from a web application. It is very common task for web developers. Here are different approaches to do it in ASP.NETC#:

Approach 1:

Using the Excel PIA (primary interop assemblies) to generate a spreadsheet server-side.

It needs Microsoft Office suite installed on your server which is not good. So it is NOT recommended.

A Better Way To Manage ASP.NET Session With Generic Wrapper

Before we get started, let us see the general way to use Session in ASP.NET

if (Session["UserName"] == null) 
{ 
    LabelUserName.Text = "Anonymous"; 
} 
else 
{ 
    LabelUserName.Text = (string)Session["UserName"]; 
} 

You can feel some drawbacks e.g. to check null reference, type safety, to cast object..etc.

Now add following class and see how it solves the issues:

Bulk Insert – Save DataTable to MongoDB – C# MongoDB Driver 2.1

Do you want to import csv or excel (xls, xlsx) file in MongoDB? You can read the file, get the data in C# datatable and save it to MongoDB using InsertBatch method. This article explains how to save C# DataTable to MongoDB for inserting a large amount of data.

To install Official .NET driver for MongoDB, run the following command in the Package Manager Console

Install-Package MongoDB.Driver

Upload and Read CSV File in ASP.NET MVC

To read CSV file doesn’t mean to use String.Split(). CSV files may contain commas, carriage returns, speechmarks…etc within strings. In this post, we will learn how to upload and read CSV File in ASP.NET MVC WITHOUT using Jet/ACE OLEDB provider. It is helpful when you have to deploy your code on shared hosting, Azure website or any server where ACE Database engine is not available. We will use a fast CSV Reader by Sebastien Lorien.

Read Also: Upload and Read Excel File (.xls, .xlsx) in ASP.NET MVC.