Dropdown Multiple DB field type

Should be an easy question to answer.

I want to implement a "Location" drop down allowing end user to select one or more locations. What is the mssql field type for storing the selections made in the field?

I have configured the dropdown:

image

as soon as I make a selection I get:

dotnet: warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
      Unhandled exception rendering component: Unable to cast object of type 'System.Linq.EnumerableQuery`1[System.Int32]' to type 'System.String'.
      System.InvalidCastException: Unable to cast object of type 'System.Linq.EnumerableQuery`1[System.Int32]' to type 'System.String'.

You are attempting to bind DropDown with multiple selection with integer set as ValueProperty which will produce IEnumerable<int> to a string property.

Setting ValueProperty to the same as the TextPropery:
image

I get:

dotnet: warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
      Unhandled exception rendering component: Unable to cast object of type 'System.Linq.EnumerableQuery`1[System.String]' to type 'System.String'.
      System.InvalidCastException: Unable to cast object of type 'System.Linq.EnumerableQuery`1[System.String]' to type 'System.String'.

Also the same error when I set like:

image

ShortLocation is text

Locations in DB is:
image

@kest874 changing ValueProperty will not change the expected value - it’s still IEnumerable since its multi select DropDown. Maybe you should extend your model with IEnumerble property, convert to a coma separated string in the property setter and from coma separated string in the property getter.

Got it, is there an example of this somewhere?

You can extend the model class with a partial class, check our docs for reference. Here is an example code of such property:

public IEnumerable<int> SelectedLocations
{
   get
   {
       return Location.Split(‘,’);
   }
   set
   {
       Location = string.Join(“,”, value);
   }
}

Attempting this:

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Reqrfepaf.Models.Sssql01
{
  public partial class User
  {
    public IEnumerable<int> SelectedLocations
    {
       get
	   {
		   return Location.Split(',');
	   }
   set
	   {
		   Location = string.Join(",", value);
	   }
    }
  }
}

I get

error CS1061: 'Location' does not contain a definition for 'Split' and no accessible extension method 'Split' accepting a first argument of type 'Location' could be found

Some background, the "Location" Field is part of the "Users" table, the locations for the drop down are in the "Locations" table.

Any light you can shed on this would be great.

What’s the type of Location property? My example code will work for string property.

User table has field Locations which is varchar(100)
Locations table is ID (INT) (PK) and ShortLocation varcvhar(50)

Idea was to use dropdown for the locations so that I can later use the selected locations to filter the grids (only allow the selected locations in their user record to be seen)

You should adapt my code to your case. Location in my code is the single string property that is mapped to the database field.

I should extend the user model yes? Or the location model?

You should extend the model that is mapped to the table you want to update.

Still having some issues, I sent an example project with the table definition and some demo data in a text file to info@radzen.com If you could modify it to work I can modify my project to work properly.

We’ve not received your application. Use a service like Google Drive to avoid large attachments. It will be better to send us your database schema and data as SQL script.

I resent it just now it has a download link to the project, and to clarify, I included a table create and a couple insert statements sql script.

Let me know if you still don't receive it.

Did you not receive the email?

I've received your email however we usually do not work during the night.

Here is how the code should look like:

Here are the DropDown settings:
image

And here is the final result:


You can get the app from here:
https://drive.google.com/file/d/1kFRGiYk7Ag1D92WrOFTU69DEgs_eZZKF/view?usp=sharing

Hi @kest874,

I would like to remind you that custom implementations are not something that we usually do as part of Radzen support. Those qualify as consulting which is not something that we provide.

Understandable I just wanted to make sure you did receive it. I wasn't looking for an answer right away.

Totally understand, did not mean for this to come across as it was a urgent issue. I would gladly pay for consultation, I just couldn't wrap my head around how to make it work without finding an example placed somewhere. You guys are first rate with an excellent product. I wouldn't have leaned as much as I have if you guys and this forum were not such an excellent resource.