Tag Helper in forms in ASP.NET Core

Add Library to _ViewImports.cshtml

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

Form Tag Helper

<form asp-controller="category" asp-action="create" method="post">

</form>

Input Tag Helper

@model SignUpModel
<form method="post">
	<p>
		<label asp-for="Username"></label>
		<input type="text" asp-for="Username" />
	</p>
	<p>
		<label asp-for="Email"></label>
		<input type="text" asp-for="Email" />
	</p>
	<p>
		<label asp-for="Password"></label>
		<input type="password" asp-for="Password" />
	</p>
	<p>
		<label asp-for="Remark"></label>
		<textarea asp-for="Remark"></textarea>
	</p>
	<p>
		<label asp-for="Province"></label>
		<select asp-items="@Model.Provinces">
			<option value="">--Select Province--</option>
		</select>
	</p>
	<p>
		<button>Sign Up</button>
	</p>
</form>

Select Province Model

Method 1

List<Proivince> list = new List<Province>{
	new Province { Id = 1, Name = "Los Angeles" },
	new Province { Id = 2, Name = "California" },
	new Province { Id = 3, Name = "Las Vegas" },
	new Province { Id = 4, Name = "Texas" },
	new Province { Id = 5, Name = "Chicago" },
};
SelectList list = new SelectList(list, "Id", "Name");

Method 2

List<SelectListItem> list = new List<SelectListItem>{
	new SelectListItem { Value = "1", Text = "Los Angeles" },
	new SelectListItem { Value = "2", Text = "California" },
	new SelectListItem { Value = "3", Text = "Las Vegas" },
	new SelectListItem { Value = "4", Text = "Texas" }
};

Select Group

SelectListGroup groupNorthAmerica = new SelectListGroup{ Name = "North America" };
SelectListGroup groupEurope = new SelectListGroup{ Name = "Europe" };
List<SelectListItem> list = new List<SelectListItem>{
	new SelectListItem { Value = "MEX", Text = "Mexico", Group = groupNorthAmerica },
	new SelectListItem { Value = "CAD", Text = "Canada", Group = groupNorthAmerica },
	new SelectListItem { Value = "US", Text = "USA", Group = groupNorthAmerica },
	new SelectListItem { Value = "FR", Text = "France", Group = groupEurope },
	new SelectListItem { Value = "GE", Text = "Germany", Group = groupEurope },
	new SelectListItem { Value = "ES", Text = "Spain", Group = groupEurope }
};