Hi RonRon,
Check this example. Now please take its reference and correct your code.
Model
public class Movie
{
public int ID { get; set; }
[Required]
public string Title { get; set; }
[DataType(DataType.Date)]
public DateTime ReleaseDate { get; set; }
public string Genre { get; set; }
public decimal Price { get; set; }
}
Controller
public class HomeController : Controller
{
public IActionResult Index()
{
Movie movie = new Movie()
{
ID = 1,
Title = "When Harry Met Sally",
ReleaseDate = DateTime.Parse("1989-1-11"),
Genre = "Romantic Comedy",
Price = 7.99M
};
return View(movie);
}
[HttpPost]
public ActionResult Index(Movie movie)
{
return View(movie);
}
}
View
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers
@model Movie_Core.Model.Movie
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link rel="stylesheet" media="screen" href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css' />
</head>
<body>
<form asp-controller="Home" asp-action="Index" method="post">
<div class="form-group">
<label asp-for="ID" class="control-label">
</label>
<input asp-for="ID" readonly="readonly" class="form-control" />
</div>
<div class="form-group">
<label asp-for="Title" class="control-label">
</label>
<input asp-for="Title" class="form-control" />
<span asp-validation-for="Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="ReleaseDate" class="control-label">
</label>
<input asp-for="ReleaseDate" class="form-control" />
<span asp-validation-for="ReleaseDate" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Genre" class="control-label">
</label>
<input asp-for="Genre" class="form-control" />
<span asp-validation-for="Genre" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Price" class="control-label">
</label>
<input asp-for="Price" class="form-control" />
<span asp-validation-for="Price" class="text-danger"></span>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success">Save</button>
</div>
</form>
</body>
</html>
Screenshot