Introduction to ASP.NET Core part 21: view components

Introduction

In the previous post we looked at partial views. Partial views have been around for a long time in ASP.NET MVC and they work in much the same way in .NET Core MVC. Partial views are a means of factoring out parts of a view into smaller, reusable and more manageable units. Partial views can also have their own dependencies. So they behave just like “full” views but are meant to be rendered within a parent view.

In this post we’ll look at an alternative to partial views called view components. View components are new in this version of MVC.

Read more of this post

Introduction to ASP.NET Core part 20: partial views

Introduction

In the previous post we looked at dependency injection in cshtml views. The @inject directive can be used to inject abstract and concrete types into views. We saw an example of the Layout view using an injected IStringFormatter interface to present some message. This abstraction was wired up in Startup.cs so that it is correctly initialised when injected. Normally though views should not depend on these services. The controller which serves up a view should pass in all the necessary arguments into it so that it can build its HTML content. So it’s a useful enhancement to the framework but use it sparingly otherwise the view will be “too clever” and perform actions it is not supposed to do.

In this post we’ll look briefly at partial views.

Read more of this post

Introduction to ASP.NET Core part 19: dependency injection into views

Introduction

In the previous post we saw some other examples of creating custom views in .NET Core MVC. We first discussed how to set the HTML content before and after some text using the “spandec” custom attribute. It enclosed a piece of text within a span element and added a class attribute to the span element as well. We then saw how easy it was to provide the custom tag with an object from the HTML markup using an attribute. Therefore we’re not confined to supplying primitive types to custom tags as arguments. Lastly we saw how to create a conditional tag helper to filter out specific Book records based on an if-condition.

In this post we’ll briefly look at dependency injection into views.

Read more of this post

Introduction to ASP.NET Core part 18: custom tag helpers cont’d

Introduction

In the previous post we started looking into custom tags. The most straightforward way of creating custom HTML tags is to derive from the TagHelper class and override its Process or ProcessAsync function. Otherwise a custom tag helper is a normal C# class, i.e. there’s no special template involved. We discussed some examples of custom attributes and elements as well.

In this post we’ll look at some more examples of custom tags. We’ll also see how to pass in an object into a custom tag as an argument.

Read more of this post

Introduction to ASP.NET Core part 17: custom tag helpers

Introduction

In the previous post we continued our exploration of the .NET Core tag library. In particular we looked at how to build a form using the library. We also saw some examples on mixing the tag library mark-up and Razor C# syntax. The tag library version of the POST form works in exactly the same way as its Razor equivalent.

The tag library is highly extensible. This implies that we can build our own custom tags. We’ll explore this with several examples in this post.

Read more of this post

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

Introduction

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

Introduction

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

ultimatemindsettoday

A great WordPress.com site

Elliot Balynn's Blog

A directory of wonderful thoughts

HarsH ReaLiTy

A Good Blog is Hard to Find

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

WEB APPLICATION DEVELOPMENT TUTORIALS WITH OPEN-SOURCE PROJECTS

Once Upon a Camayoc

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: