How do I input multiple values to the database from HTML multiple Attributes? In this problem I want to input multiple values in MultiSelectList in one column in the database table, namely the Pages column. And then about the form update to display the options that have been previously selected? I am using ASP.NET MVC with a MySQL database. Thank's
Create.cshtml
<div class="box-body">
<form class="form-horizontal" method="post" action="CreatePage">
<table class="table table-striped">
<tr>
<td>Page</td>
<td><select class="form-control select2" multiple="multiple" style="width: 100%;" name="Page">
<option value="Home">Home</option>
<option value="About">About</option>
<option value="Profile">Profile</option>
</select>
</td>
</tr>
</table>
<div class="box-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
CreateController.cs
[HttpPost]
public ActionResult CreatePage(MasterPage Page)
{
db.MasterPage.Add(Page);
db.SaveChanges();
return RedirectToAction("Index","Home");
}
public ActionResult Create()
{
return View();
}
MasterPage.cs
public partial class MasterPage
{
public string Page { get; set; }
}