This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
var builder = services.AddMvcCore(); | |
builder.AddJsonFormatters(); | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
{ | |
if (env.IsDevelopment()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HomeController : Controller | |
{ | |
public JsonResult Index() | |
{ | |
return Json(new { Name = "John Smith", Country = "USA", Designation = "Software Engineer" }); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HomeController : Controller | |
{ | |
public string Index() | |
{ | |
return "Hello from MVC | Coreprogram"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.UseStaticFiles(); | |
app.UseMvcWithDefaultRoute(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
// If you are using .NET Core SDK 2.2 | |
services.AddMvc(); | |
// OR If you are using .NET Core 3.0 or 3.1 then you need to customize the AddMVC() like this. | |
services.AddMvc(options => options.EnableEndpointRouting = false); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CustomerController : Controller | |
{ | |
private CustomerRepository _customerRepository; | |
public CustomerController(ICustomerRepository customerRepository) | |
{ | |
_customerRepository = customerRepository; | |
} | |
public IActionResult Details(int id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model CustomerManagement.Customer | |
<html> | |
<head> | |
<title>Customer Details</title> | |
</head> | |
<body> | |
<table class="has-fixed-layout" style="width:50%"> | |
<thead> | |
<tr><th colspan="2">Customer Details</th></tr> | |
</thead> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Customer | |
{ | |
public int Id { get; set; } | |
public string Name { get; set; } | |
public string Address { get; set; } | |
public string Mobile { get; set; } | |
} | |
public interface ICustomerRepository | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
// If the environment is Development serve Developer Exception Page | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
// else serve User Friendly Error Page with Application Support Contact Info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task Invoke(HttpContext httpContext) | |
{ | |
await httpContext.Response.Body.WriteAsync(Encoding.ASCII.GetBytes("Called from Custom Middleware -- ")); | |
await _next.Invoke(httpContext); | |
} |
NewerOlder