Introduction to ASP.NET Core part 16: tag helpers cont’d with forms


In the previous post we started discussing a new feature in .NET Core MVC, namely tag helpers. There are numerous tag libraries available out there but for .NET it’s something new. The built-in tag library allow us to create dynamic URL using more HTML elements and attributes and less C#. The current version of the tag library offers many HTML-based alternatives of the Html helpers. The tag library elements are transformed into real HTML on the server side so the end users never get to see them and there’s no need for any magic JavaScript library to convert attributes such as “asp-action” into “href” on the client side. Occasionally though we have to revert back to using the Html helpers since not all functionality is available through the tag library yet. We can however expect it to grow more and more in the future as .NET Core matures. Using either the Html helpers or the tag library is largely a matter of taste. If you’re fine with a lot of C# in the Razor views then go with the Html helpers.

In this post we’ll continue to explore the built-in tag library and build a form using the asp tags.

Read more of this post

Introduction to ASP.NET Core part 15: starting with tag helpers


In the previous post we discussed a special type of view file in .NET Core MVC called _ViewStart.cshtml. This file can include a C# Razor code block which is executed before the concrete view files are rendered. The most common usage of the view start file is to declare the layout used for that view. That discussion brought us to layout files and how they can help us factor out common HTML markup from the views. Common HTML markup includes menu items, navigation bars, footers and the like. The content of the concrete view file is injected into the layout file using a method called RenderBody. The RenderSection function adds a named section in the layout that the views can implement with a names section directive.

In this post we’ll start covering a new feature in .NET Core MVC called tag helpers. It’s quite a sizable new topic in MVC .NET so we’ll dedicate multiple posts to these helpers since not even experienced ASP.NET MVC developers have been exposed to them.

Read more of this post

Introduction to ASP.NET Core part 14: the view start and the layout files


In the previous post we looked at a special kind of view file called _ViewImports.cshtml. It is special in a way that MVC knows about this file and will pick it up during execution. We don’t need to register the file anywhere, we just need to put it in a folder where the views are stored. The view imports file has a very specific role. We can put a number of C# using statements that will be executed in all view cshtml files where the view imports file is applied. We can have multiple _ViewImports file in the project. We can have one in each folder containing the views, like /Views/Books, /Views/Customers etc. and each view file in those folders will pick up the view imports file in that folder. We can also have an overall view imports file in the Views folder as well. That imports file will be applied to every single view within the Views folder and its subfolders.

In this post we’ll look at another special file called _ViewStart.cshtml. We’ll also talk a bit about the layout file since it is strongly related to the view start file.

Read more of this post

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


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

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


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

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


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

Introduction to ASP.NET Core part 10: the details page and more on view models


In the previous post we looked more closely at routing in .NET Core MVC. There are two ways two declare the routing rules: imperatively via Startup.cs or declaratively in the controllers using attributes. The routing rules can be distributed with this solution. General routing rules like the Default route can be placed in Startup.cs, whereas controller and action method specific rules can be declared in the controllers directly.

In this post we’ll continue building on our demo application. We’ll add a details page for the books and we’ll also see our first Razor HTML helper method in action.

Read more of this post


A great 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: