ASP.Net Core MVC: Bind Model inside View

on Mar 06, 2022 07:36 PM

I Am trying to create a form to collect the qualifications of students. at first, the list should contain 4 objects for four different qualifications.

//the segment of the *create view*
@for (var i = 0; i < 4; i++)
    <div class="col-md-3 me-2">
        <label asp-for="@Model[i].Institute" class="control-label col-md"></label>
        <input asp-for="@Model[i].Institute" class="form-control" />
        <span asp-validation-for="@Model[i].Institute" class="text-danger"></span>

    <div class="col-md-3 me-2">
        <label asp-for="@Model[i].YearGraduated" class="control-label"></label>
        <input asp-for="@Model[i].YearGraduated" class="form-control" />
        <span asp-validation-for="@Model[i].YearGraduated" class="text-danger"></span>
<div class="form-group d-flex-row m-auto mt-2">
    <input type="submit" name="submit" value="Save and Continue" />


public IActionResult Create()
    var model = new List<Qualification>();
    model = _context.Qualifications.ToList();
    return View(model);

 My problem is when I run the code, nothing is generated and no error at all.

Can anyone help

Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Mar 07, 2022 01:27 AM

Hi benuklemi,

Check this example. Now please take its reference and correct your code.


public class PersonModel
    public int Id { get; set; }
    public string Name { get; set; }
    public string Country { get; set; }


public class HomeController : Controller
    public IActionResult Index()
        List<PersonModel> persons = new List<PersonModel>();
        persons.Add(new PersonModel { Id = 1, Name = "John Hammond", Country = "United States" });
        persons.Add(new PersonModel { Id = 2, Name = "Mudassar Khan", Country = "India" });
        return View(persons);


@model List<List_Model_Core_MVC.Models.PersonModel>
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
    Layout = null;

<!DOCTYPE html>

    <meta name="viewport" content="width=device-width" />
    <link rel="stylesheet" href="" />
    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
    <div class="container">
        @for (int i = 0; i < Model.Count(); i++)
            <div class="row">
                <div class="col-md-3 me-2">
                    <label asp-for="@Model[i].Id" class="control-label col-md"></label>
                    <input asp-for="@Model[i].Id" class="form-control" />
                    <span asp-validation-for="@Model[i].Id" class="text-danger"></span>

                <div class="col-md-3 me-2">
                    <label asp-for="@Model[i].Name" class="control-label"></label>
                    <input asp-for="@Model[i].Name" class="form-control" />
                    <span asp-validation-for="@Model[i].Name" class="text-danger"></span>

                <div class="col-md-3 me-2">
                    <label asp-for="@Model[i].Country" class="control-label"></label>
                    <input asp-for="@Model[i].Country" class="form-control" />
                    <span asp-validation-for="@Model[i].Country" class="text-danger"></span>