Posts

Showing posts with the label ASP.NET Core

ASP.NET Core : Adding The Default View With _ViewStart.cshtml

Image
In ASP.NET MVC there is a default layout file that the application use when one exists.  If you look at the markup at the top of the "Index.cshtml" file you will see that there is a markup to specify the layout of the page in the code below. @{ Layout = null; } The code above tells ASP.NET MVC to not assign any layout to the page because it is being set to null. In this blog we will build on our existing NorthwindCafe.Web    project and add a default layout view to the project so that each page in the project will have a common layout.  This is similar what you would a master page for in web forms.

ASP.NET Core : Create Our First Controller and View

Image
In the previous post we have enabled MVC on our application.  Now we want to add our first MVC controller and view to test out verify that MVC is working.  We also have to tell ASP.NET Core what pattern to look for when looking for our controllers and views. Step-By-Step Instructions: 1.  Add a folder call "Controllers" in the root of your application 2. Right click on the "Controllers" folder and select "Add" → "New Item" → .NET Core → MVC Contoller Class, then click "Add" 3.  You see the "HomeController.cs" class being added to the "Controllers" folder 4.  Double click on the "HomeController.cs" file and you will see the following code using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; namespace NorthwindCafe.Web.Controllers { public class HomeController : Controller { // GET: / / public IActionResult Ind...

Enable MVC On ASP.NET Core Application

Image
In this post we will go over the process of enabling ASP.NET MVC in our application.  Just like static files, in order for us to use MVC in our application we have to tell ASP.NET Core to use in the Startup.cs file.  We will continue to use the application "NorthwindCafe" that we used in our previous blog. Here are the steps to add MVC to your application: 1.  Open the Startup.cs file, then in "ConfigureServices" method type in the following to enable MVC public void ConfigureServices(IServiceCollection services) { services.AddMvc(); } 2. As with the static files, there will be a red underline on the .AddMvc() method that's because we haven't added the package to your project yet.  So click on the yellow light and select the first option to add Microsoft.AspNET.Mvc package to our project. 3.  Now go into the Configure method and type app.UseMvc() into the method, the final markup should look like the following publ...

Enable ASP.NET Core to Serve Static Files

Image
As I have mentioned before ASP.NET Core decouples the application from the infrastructure as much as possible.  Therefore, you have to tell it exactly what you want in your project.  In this blog post we are going to tell ASP.NET that we want to serve static html files in our application. Here are the steps to serve static files in our ASP.NET Core application. 1.  Open the "NorthwindCafe.Web" project, then click on the "Startup.cs" file in the project.  You will see the following markup in the Configure method public void Configure(IApplicationBuilder app) { app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); }); } 2.  Go into the Configure method, remove the existing code and type in the following code public void Configure(IApplicationBuilder app) { app.UseStaticFiles() } You will notice that the app.UseStaticFil...

ASP.NET Core : Add jQuery, Bootstrap, AngularJS Using bower.json

Image
In this blog post we are going to add the jQuery, AngularJS, and bootstrap libraries to our ASP.NET Core application.  Normally we will use NuGet to bring in these libraries but ASP.NET Core gives you the option to use bower to configure the dependencies that you will need on the client-side. Here are the steps to import the client-side dependencies into our project: 1. First let's make bower.json part of the "NorthwindCafe.Web" project, by right click on the bower.json file, and then choose "Show in Solution Explorer" 2.  Open the bower.json file the markup should look like this { "name": "asp.net", "private": true, "dependencies": { } } 3. Change the markup to look like the following { "name": "asp.net", "private": true, "dependencies": { "bootstrap": "~3.3.6", "angular": "~1.5.7" } } 4. Save the bower.js...

How To Create An ASP.NET Core Application From Scratch

Image
Technology has moved at a breakneck speed, after working with ASP.NET Core for a while, I realized that my ASP.NET MVC blog articles have become outdated.  Don't get me wrong, MVC is still a very big part of ASP.NET Core, but that's the thing it's just a part of it.  ASP.NET Core has decoupled the infrastructure from the application.  You can deploy your web app on Docker imagine that!  No longer is IIS your primary means of hosting your ASP.NET application. However, with this new freedom comes added complexity.  No longer can you just drag and drop components into your design surface.  Those days are long gone.  This post ist meant to ease your way into ASP.NET Core.  I will using the release candidate version two of ASP.NET Core for this post and other subsequent posts.  Don't be surprise if I update the version midstream because the product is still pre-release.  I will be using Visual Studio 2015 for my development.  You can use...