Reputation: 1591
I'd appreciate if someone could help with my issue.
I have an entity with field PAYMENT_CURRENCIES
of string
type, that should store comma separated values, i.e. "USD,EUR,AED" (or any other separation char).
In my View:
@Html.Kendo().MultiSelectFor(model => model.Contract.PAYMENT_CURRENCIES).BindTo(context.Currencies).DataTextField("CODE").DataValueField("CODE").Placeholder("Add currency...")
The problem is when I submit the form i receive only first selected value in the Controller
.
I would not like to change the datatype of the field for IEnumerable
.
Is there a way to receive all selected values as a string with some separator?
Thanks a lot
Upvotes: 1
Views: 3451
Reputation: 3154
Add an array-property to your model:
public string[] PAYMENT_CURRENCIES_LIST
{
get
{
return PAYMENT_CURRENCIES?.Split(',');
}
set
{
PAYMENT_CURRENCIES = string.Join(",", value);
}
}
Then use this property in your view:
@Html.Kendo().MultiSelectFor(model => model.Contract.PAYMENT_CURRENCIES_LIST)...
So the array-property maps to the Kendo-Multiselect and translates the values to/from the original field.
Upvotes: 1
Reputation: 13
I had the same requirement as yours, & couldn't find a decent solution, That's how I solved it:
public List<string> SelectedCurrencies { get; set; }
@Html.Kendo().MultiSelectFor(model => model.SelectedCurrencies)
.BindTo(context.Currencies)
.DataTextField("CODE")
.DataValueField("CODE")
.Placeholder("Add currency...")
PAYMENT_CURRENCIES = string.Join(",", viewModel.SelectedCurrrencies);
SelectedCurrencies = PAYMENT_CURRENCIES.Split(',').ToList();
Upvotes: 0
Reputation: 213
I don't think that you can automatically convert your multi select input value(s) to a single string.
So what you can do is:
Upvotes: 1