My goal is to make my selection lists, that are countries that load states, that can also select multiple, go into the same col/row in the database with say a comma in between each ID.
My expected result is to not have only the last one in the user input selection in the MultiSelectionList go into the database which is my current situation.
There are no error messages but I don't have the slightest clue on any more things that I could try.This is my first time using MVC and the HTML helpers but my code is below.
<tr>
<td>
<p>Location Countries (hold CTRL to select multiple countries):</p>
</td>
<td>
@Html.DropDownListFor(model => model.Vendor.CompanyCountry, (MultiSelectList)ViewBag.Country, new Dictionary<string, Object> { { "data-stateId", "Vendor_CompanyState" }, { "class", "toFilter" }, { "multiple", "multiple" } })
</td>
</tr>
<tr>
<td>
<p>Location States (hold CTRL to select multiple states):</p>
</td>
<td>
@Html.DropDownListFor(model => model.Vendor.CompanyState, new MultiSelectList(ViewBag.StateOld, "Value", "Text", ViewBag.VendorState), "Select State", new { multiple = "multiple" })
</td>
</tr>
The specific line that inputs into data base is
@Html.DropDownListFor(model => model.Vendor.CompanyCountry, (MultiSelectList)ViewBag.Country, new Dictionary<string, Object> { { "data-stateId", "Vendor_CompanyState" }, { "class", "toFilter" }, { "multiple", "multiple" } })
And here
@Html.DropDownListFor(model => model.Vendor.CompanyState, new MultiSelectList(ViewBag.StateOld, "Value", "Text", ViewBag.VendorState), "Select State", new { multiple = "multiple" })
I'm thinking where
model => model
Something may have to change?
Do you "post" a string? Consider to use String[].
// controller
public IActionResult UpdateData(string[] CompanyState)
{
}
I would also use html tags and asp-helpers instead of @Html.Helpers to have:
<select name="CompanyState" id="CompanyState" multiple="multiple">
<option>Select</option> // empty value
@foreach(var item in (MultiSelectList)ViewBag.VendorState)
{
<option value="@item.Value">@item.Text</option> // dont remember if it was good cast - please verify
}
</select>