Enables to define application's URL naming patterns that work well for search engine optimization
routes.MapRoute("default", "api/{controller}/{action}");
[Route("api/[controller]")]
[AllowAnonymous]
public class PasswordController : ControllerBase
{
Attribute routing : to specify routing information by decorating controllers and actions with attributes that define application's routes
public async Task<IActionResult> Save() {...}
Converts client request data (form values. route data, query string parameters, HTTP headers) into objects that controller can handle.
//LoginController action
public async Task<IActionResult> Login(LoginModel model)
{
if (ModelState.IsValid)
{
// Validate PIN.
var chars = model.Pin
.Where(c => !char.IsWhiteSpace(c))
.Select(c => char.ToUpperInvariant(c))
.ToArray();
......
}
//LoginModel
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace MyIPCS.Listing.SL.Models
{
public class LoginModel
{
[Required(ErrorMessage = "Sila masukkan PIN")]
public string Pin { get; set; }
public Guid? Sid { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;