View
<form method="post">
@(await Html
.SimpleGrid(Model.Take(5))
.AddColumn(col => col
.DisplayAs(movie =>
$"<input type='hidden' name='Movies.Index' value='{movie.Name}'>" +
$"<input type='hidden' name='Movies[{movie.Name}].Name' value='{movie.Name}'>" +
$"{movie.Name}")
.Header("Movie")
.Encoded(false))
.AddColumnFor(movie => movie.Director)
.AddColumn(col => col
.DisplayAs(movie =>
$"<input class='form-control' type='text' name='Movies[{movie.Name}].Director' value='{movie.Director}' />")
.Header("Edit Director")
.Encoded(false))
// This works as well:
//.AddColumn(col => col
// .DisplayHtmlContent(movie =>
// Html.TextBox($"Movies[{movie.Name}].Director", $"{movie.Director}", new { @class = "form-control" })))
.RenderAsync())
<button class="btn btn-primary">Submit</button>
</form>
Controller
[HttpGet]
public IActionResult Form2()
{
return View(MovieQuery);
}
[HttpPost, ValidateAntiForgeryToken]
public IActionResult Form2(Movie[] movies)
{
return View(movies.AsQueryable())
.Success($"Received: {movies.Length} movies");
}