Add jQuery DataTables grid to an ASP.NET Core MVC web application

ASP.NET does not provide sortable, searchable tables. jQuery DataTables is a popular way to display user-friendly data in an ASP.NET Core MVC web application. Set up the environment Add the System.Linq.Dynamic.Core NuGet package to the web application Add the JsonOptions to the Startup.cs file using Newtonsoft.Json.Serialization; Add the AddJsonOptions to the services.AddMvc() section in the ConfigureServices() method of the Startup.cs file .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()); Add …

Error unprotecting the session cookie in an ASP.NET Core MVC application.

The new ASP.NET Core MVC framework automatically displays a message for the user to accept the application’s privacy policy. The default message is “Use this space to summarize your privacy and cookie use policy.” No cookies are saved in the user’s browser until they click the Accept button. Even after accepting the terms, if the browser …

Set the environment for an ASP.NET Core MVC web application

When the ASP.NET Core MVC web application starts, reads the name of the environment for an environment variable of the host computer. The compiled application contains the configuration for all supported environments, making possible to build and deploy the same artifact in every environment. If the ASPNETCORE_ENVIRONMENT environment variable is not defined, the Production environment settings are …

Enable .NET Core Entity Framework Linq query execution

When we create a new .NET Core class it only contains the using System; reference. To enable Linq database queries in a .NET Core project, add using System.Linq; using System; using System.Linq; To enable the usage of .Include() in the Linq queries, add using Microsoft.EntityFrameworkCore;  

Return values to the controller in the model from the ASP.NET MVC view

When we create an ASP.NET MVC web application, the model (an object) is the easiest way to return values from the view to the controller. For the view to be able to return the values in the model, make sure the model contains properties, not fields, for every value with { get; set; } public class MyViewModel { public …

Reverse engineer a database with AspNetCore in Visual Studio

For some reason the .NETCore designers did not think, that developers want to follow best practices by separating the data layer from the presentation layer. The Entity framework out of the box only works if the database is accessed from the main application project. When we try to reverse engineer a PostgreSQL database from a …

Procedure or function ‘`…_Insert`’ cannot be found in database …

When you use the Microsoft .NET Entity framework to access a MySql database, the autogenerated code throws an error when you try to insert a row into the database with context.MY_TABLE.Add(MY_OBJECT); Server Error in ‘/’ Application. Procedure or function ‘`…_Insert`’ cannot be found in database ‘`…`’. Description: An unhandled exception occurred during the execution of …

No connection string named ‘…’ could be found in the application config file.

Two-tier applications separate the presentation layer and the data layer, and all database access related objects are located in the data-tier. When the application runs, the config file of the main project is read. In web applications, it is the web.config, in console applications the app.config file. When you get the following runtime exception Exception thrown: ‘System.InvalidOperationException’ in …

The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)

When I made changes to the web.config file of an ASP.Net C# application, I have accidentally deleted a comma, and I started to get the runtime error message: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) Make sure all necessary commas are there in the config files, Visual Studio does not …

Connect to a MySQL database from Visual Studio 2017

As of today weI can connect to a MySQL database, but cannot generate the Entity Data Model from a MySQL database in Visual Studio 2017 To access a MySQL database from Visual Studio 2017 IMPORTANT: First install MySQL for Visual Studio, and after that install MySQL Connector/Net. If MySQL Connector/Net is already installed on your workstation, uninstall …