Introduction to ASP.NET Core part 13: the view imports file

Introduction

In the previous post we looked at data annotation to refine our view models. Data annotations are attributes that can be applied to properties of the view models that are injected into the views. These attributes can be put into three groups: validation, display and data type attributes. Validation attributes can help us filter out the most obvious bad entries from the forms. They can make a field required or they can declare that a property must have a certain minimum and/or maximum value. The Display attribute changes the corresponding property label in the view. The data type attributes declare what kind of editor a certain property needs. E.g. the URL data type gives a hint to the view to render an input of type URL. If the browser has built-in validation for the various input types then it offers an extra layer of validation.

In this post we’ll discuss a very specific view file called the view imports file. As usual we’ll be working in our demo web application DotNetCoreBookstore.

Read more of this post

Joining common values from two sequences using the LINQ Intersect operator

Say you have the following two sequences:

string[] first = new string[] {"hello", "hi", "good evening", "good day", "good morning", "goodbye" };
string[] second = new string[] {"whatsup", "how are you", "hello", "bye", "hi"};

If you’d like to find the common elements in the two arrays and put them to another sequence then it’s very easy with the Intersect operator:

IEnumerable<string> intersect = first.Intersect(second);
foreach (string value in intersect)
{
	Console.WriteLine(value);
}

The ‘intersect’ variable will include “hello” and “hi” as they are common elements to both arrays.

Read more of this post

Introduction to ASP.NET Core part 12: data annotation of view models

Introduction

In the previous post we went through how to insert a new Book entity using a form. We used a view model for this purpose. Two different Create action methods take care of the insertion process in the Books controller. One accepts HTTP GET requests and only presents an empty form with the various book insertion view model properties. The corresponding view has a form that’s built using a Html helper which takes care of setting up the form with the correct naming conventions so that the view model properties can be correctly populated. We also extended our rudimentary layered architecture to simulate that the Book entity is saved in a data store. Finally we also mentioned the usage of the anti-forgery token attribute which guards against a cross site request forgery attack.

In this post we’ll look at how attributes on our attributes can help us refine our view models and how they are rendered in the view.

Read more of this post

Data type conversion in F#

F# has much the same primitive data types as C#. Here are some examples:

let integer = 123
let floating = 23.
let dec = 24M
let bool = true
let text = "This is some string"
let character = 'c'

Occasionally we may need to convert one primitive type to another.

Read more of this post

Infix operators in F#

F# makes the distinction between “prefix” and “infix” functions. The word prefix means that something comes before something else. Prepositions in many Indo-European languages, like “in”, “for” and “on” in English are examples of prefixes, they are placed in front of another word, most often a noun: in the house, at the station, for that purpose.

Prefix functions are how we most often define and call functions in F#. The function name comes first which is then followed by the function arguments.

Here’s a function that adds two numbers:

let addTwoNumbers x y = x + y

Unsurprisingly we call the above function as follows:

Read more of this post

An overview of grouping collections with LINQ in .NET

Introduction

The LINQ GroupBy operator is one of the most powerful ones among all LINQ operators. It helps us group elements in a collection in various ways and lets us control the element and result selection process. However, with its many overloads and Func parameters the GroupBy operator can be a bit difficult to understand at first. At least it is more complex than say the Min() and Max() LINQ operators.

This post will go through the GroupBy operator and many of its overloads with a number of examples.

Read more of this post

Introduction to ASP.NET Core part 11: inserting a new Book in a form

Introduction

In the previous post we continued our exploration of MVC in ASP.NET Core by building a details page for the books. We can now click a link for each Book view model in the table and view some more details about the selected book. We also rearranged the code and introduced rudimentary layers of a controller, a service, a domain and a repository for our Book entity. Then we exposed ourselves to the first example of a HTML helper in the Index and Details Razor views with the anchor tag builder. HTML helpers are very useful tools in Razor that help us build dynamic HTML. If you used Razor views before then this is nothing new to you.

In this post we’ll continue on the same path as in the previous part. We’ll build a view to insert a new book entity. We’ll see a couple more HTML helpers to make model binding easier.

Read more of this post

ultimatemindsettoday

A great WordPress.com site

iReadable { }

.NET Tips & Tricks

Robin Sedlaczek's Blog

Developer on Microsoft Technologies

HarsH ReaLiTy

A Good Blog is Hard to Find

Ricos Blog zu Softwaredesign- und architektur

Ideen und Gedanken rund um Softwaredesign und -architektur, Domain-Driven Design, C# und Windows Azure

the software architecture

thoughts, ideas, diagrams,enterprise code, design pattern , solution designs

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

Anything around ASP.NET MVC,WEB API, WCF, Entity Framework & AngularJS

Cyber Matters

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: