Hi rani,
Refer below example.
Model
public class CustomerModel
{
public int Id { get; set; }
public string Name { get; set; }
}
Controller
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult Simple(int id)
{
return Content($"ID: {id}");
}
public IActionResult Complex(CustomerModel model)
{
return Content($"ID: {model.Id + Environment.NewLine}Name: {model.Name}");
}
}
View
@model Model_Binding_MVC_Core.Models.CustomerModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<h3>Simple</h3>
@using (Html.BeginForm("Simple", "Home", FormMethod.Post))
{
<input type="text" name="id" value="" />
<button type="submit">Submit</button>
}
<h3>Complex</h3>
@using (Html.BeginForm("Complex", "Home", FormMethod.Post))
{
<span>ID : </span> @Html.TextBoxFor(m => m.Id)
<br />
<span>Name : </span>@Html.TextBoxFor(m => m.Name)
<button type="submit">Submit</button>
}
</body>
</html>
Screenshot
For more details refer below link.
https://www.c-sharpcorner.com/article/asp-net-core-2-0-mvc-model-binding/