ASP.Net Core - Full Application - Part 21.pdf - ASP.NET...

This preview shows page 1 - 13 out of 64 pages.

ASP.NET Core Full Application Example
Improving the URL Displaying URL links like these looks ugly We can prettify them to something like We can add multiple routes with our endpoint routing, and also can me them prettified as well. Important that you add the new route before the Default one that is already in the method. The routing system processes routes in the order they are listed. This is the only alteration required to change the URL scheme for book pagination.
………//Only Configure Method in the Startup.cs is displayed here public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseStatusCodePages(); app.UseStaticFiles(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute(name: "pagination", pattern: "Books/Page/{Page}", defaults: new { Controller = "Book", action = "List" }); endpoints.MapControllerRoute("default", "{controller=Book}/{action=List}/{id?}"); }); SeedData.EnsurePopulated(app); } } } .Net2.1 OR 2.2 Route.Maproute( name:”pagination”, pattern: "Books/Page/{page}", default: new {Controller = "Book" , action="List"});
You can also observe one more thing that if in the URL instead of giving page number you say something else like it will display the default page route, we can change that behavior as well so if something else given instead of a number the application properly render 404 error: page not found. A small change in the newly created route is needed endpoints.MapControllerRoute(name: "pagination", pattern: "Books/Page/{Page:int}", defaults: new { Controller = "Book", action = "List" }); Try now with
Installing the BootStrap Package First we need to create a folder on the root of the project and name it wwwroot ”. [if you already have it then don’t create it again] Then we need to create three folders in it. lib css js
Then right-click on the lib folder and go to Add Client-Side Library
Change the provider to unpkg Type bootstrap in the Library field Once you select the bootstrap it will show you all the available files in this package Makesure your target location is correct Don’t forget to click Install
Now inside the bootstrap package we are going to install jquery jquery-validate jquery-validation-unobtrusive Provider Library Target Location Install
Provider Library Target Location Install jquery-validate Package
jquery-validation-unobtrusive Package Provider Library Target Location Install
css Package Provider Library Target Location Install After installing the lib packages now right-click on the css folder and install the packages for it as well.
Styling the Contents Let us apply some bookstrap styles to our _Layout.cshtml <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <link rel="stylesheet" asp-href-include="/lib/bootstrap/dist/**/*.min.css" asp-href-exclude="**/*-reboot*,**/*-grid*" /> <title>My Book Store</title> </head> <body> <div>

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture