#ASP.NET CORE-View Components

What is View Components ?

ViewComponents are similar to partial view,that helps you to write reusable components.

Definition According to documentation:

New to ASP.NET Core MVC, view components are similar to partial views, but they are much more powerful. View components don’t use model binding, and only depend on the data you provide when calling into it.

View Components :

ViewComponents consists of two parts

1.Class derived from ViewComponent.

2.Result  returned from ViewComponent typically a view.

Creating a View-Component :

Let’s create a simple view component. They can be created in any of  ways listed below,

1.Derived from View Component class.

2.Decorate with ViewComponent Annotation.

3.class suffixed with ViewComponent.

A sample View Component would look like below:

public class SimpleViewComponent : ViewComponent
public IViewComponentResult Invoke()
return View();


Creating a View for ViewComponent :

The runtime searches for the view in the following paths:

  • Views/<controller_name>/Components/<view_component_name>/<view_name>
  • Views/Shared/Components/<view_component_name>/<view_name>

Let’s create a sample view named Default.cshtml which says “Hello Simple View Component” in the shared folder for the viewcomponent.


Invoking ViewComponent in the view : 

ViewComponent can be be called from view using @Components synchronously/asynchronusly with viewcompanent name.

@await Component.InvokeAsync("Simple")

You can download the sample code from github below






#.NET CORE Basics-project.json in MVC

The project.json file is the place where you add the dependencies with respect to your project. By default .NET Core loads only the necessary dependency/dnx, its quite different from the way the previous version of .NET(loads all dependency irrespective of usages).

Structure of project.json :


Dependencies :

By default .NET Core loads only required dependencies in the project,to add reference or dependencies to project this is the place where you declare the references . It generally contains the dependency name and version.The packages are pulled automatically as Nuget Packages.

Frameworks :

Specify the version of .NET being used,for instance .NET Core /.NET 4 etc..


PublishOptions :

This region will let you define what to include/exclude the items that are being published with IIS server.


Scripts :

This region specifies the build automation for scripts(like installing gulp,trunk etc..).All the commands defined in the scripts will be executed before the site get published in the server(prepublish).For instance “bower install” refers to install bower before publishing the package.






Getting Started with ASP.NET CORE 1

There has been significant changes in .NET after the RC of ASP.NET 5/CORE 1. In this article,i will introduce the project structure  of ASP.NET CORE Web Application.

Installation :  

1.ASP.NET Core 1 requires VS 2015 – Community and Free Edition

Getting Started :

When you create a new web application,the project structure looks like below.


The highlighted regions defines the behavior of application.I would be covering each of these in detail in the next article.

Purpose/Definition of Regions Highlighted:

global.json : Configuring the solution as a whole.Contains two section projects and sdk.

wwwroot : All the UI related Components(JS+HTML+CSS).

project.json :All the project dependencies and references to project are added here.

startup.cs : Application start up region where you resolve the dependencies and add services to project.