I want to do insert multiple input with same name with entity framework. I try this but not work
Model
public class Skill
{
[Key]
public int skill_id { get; set; }
public string skill_name { get; set; }
}
View
@model WebApplication1.Models.Skill
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<input type="text" name="skill_name[0]" id="skill_name[0]" />
<input type="text" name="skill_name[1]" id="skill_name[1]" />
<input type="submit" value="Submit" />
}
Controller
ProductContext db = new ProductContext();
[HttpPost]
public ActionResult Save(IList<Skill> skills)
{
foreach (var item in skills)
{
db.Skills.Add(skills);
db.SaveChanges();
}
return RedirectToAction("index");
}
dbContext
public class ProductContext : DbContext
{
public DbSet<Skill> Skills { get; set; }
}
How could I do? I find this https://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/ but this tutorial does not have controller example for insert