title: Split Comma to Insert Multiple Row into Database (ASP.NET MVC)
body: <p>I have one of the tables with the attributes: id, school name, student name. I want to insert new item look like: </p>
  
  <p>School Name : Elementary School (Select List)</p>
  
  <p>Students Name : A, B, C, D (TextBox)</p>
  
  <p>Join Date : 1/1/2020 </p>
  
  <p>And then table entries look like:</p>
  
  <pre><code>id  | school_name       | student_name  | join_date
  ----+-------------------+---------------+----------------
  1   | Elementary School | A             | 1/1/2020
  2   | Elementary School | B             | 1/1/2020
  3   | Elementary School | C             | 1/1/2020
  4   | Elementary School | D             | 1/1/2020
  </code></pre>
  
  <p>Model studentdb.cs</p>
  
  <pre><code>public partial class studentdb
  {
          public int id { get; set; }
          public string school_name { get; set; }
          public string student_name { get; set; }
          public DateTime join_date { get; set; }
  } 
  </code></pre>
  
  <p>CreateController.cs</p>
  
  <pre><code>[HttpPost]
  public ActionResult CreateStudent(studentdb Student)
  {
      string str = Student.studentdb;
      string[] splitstr = str.Split(',');
  
      foreach(string s in splitstr)
      {
           db.studentdb.Add(Student);
      }
  
      db.SaveChanges();
  
      return RedirectToAction("Index", "Create");
  }
  </code></pre>
  
  <p>Create.cshtml</p>
  
  <pre><code>&lt;form class="form-horizontal" method="post" action="CreateStudent"&gt;
              &lt;div&gt;&lt;a href="#" id="addNew"&gt;Add New&lt;/a&gt;&lt;/div&gt;
              &lt;table class="table table-striped"&gt;
  
                  &lt;tr&gt;
                      &lt;td&gt;School Name&lt;/td&gt;
                      &lt;td&gt;
                        &lt;select class="form-control" name="school_name"&gt;
                          &lt;option&gt;Elemtary School&lt;/option&gt; 
                          &lt;option&gt;Junior High School&lt;/option&gt; 
                        &lt;/select&gt;  
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Name&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" class="form-control" name="student_name" required&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;Join Date&lt;/td&gt;
                      &lt;td&gt;
                          &lt;div class="input-group"&gt;
                              &lt;div class="input-group-addon"&gt;
                                  &lt;i class="fa fa-calendar"&gt;&lt;/i&gt;
                              &lt;/div&gt;
                              &lt;input type="text" class="form-control pull-right"  name="join_date" required&gt;
                          &lt;/div&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
              &lt;div class="box-footer"&gt;
                  &lt;button type="submit" class="btn btn-primary"&gt;Submit&lt;/button&gt;
              &lt;/div&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>What should I do for this controller? Thanks</p>