Hi,
I'm using a multiple-selection listbox to enhance a list of GUIDs, but the controller only receives one value and not all of the selected ones in the listbox.
View:
@Html.EJS().ListBoxFor(m => m.IdAziendeTrasportatrici, Model.IdAziendeTrasportatrici).CssClass("form-control-grid").SelectionSettings(new Syncfusion.EJ2.DropDowns.ListBoxSelectionSettings { Mode = Syncfusion.EJ2.DropDowns.SelectionMode.Multiple, ShowCheckbox = true }).DataSource((IEnumerable<object>)ViewBag.AziendeTrasportatrici).Fields(new Syncfusion.EJ2.DropDowns.ListBoxFieldSettings { Text = "RagioneSociale", Value = "IdAziendaTrasportatrice" }).Render()
ViemModel:
public List<Guid> IdAziendeTrasportatrici { get; set; }
Are there any news?
@using (Html.BeginForm())
{
@Html.EJS().Button("element").Content("Button").Render()
<br />
@Html.EJS().ListBoxFor(model => model.CountyId).CssClass("form-control-grid").SelectionSettings(new Syncfusion.EJ2.DropDowns.ListBoxSelectionSettings { Mode = Syncfusion.EJ2.DropDowns.SelectionMode.Multiple, ShowCheckbox = true }).DataSource((IEnumerable<object>)ViewBag.data).Fields(new Syncfusion.EJ2.DropDowns.ListBoxFieldSettings { Text = "Name", Value = "Name" }).Render()
}
|
public class Countries
{
public string Name { get; set; }
public string Code { get; set; }
public string[] CountyId { get; set; }
public List<Countries> CountriesList()
{
List<Countries> country = new List<Countries>();
country.Add(new Countries { Name = "Australia", Code = "AU" });
country.Add(new Countries { Name = "Bermuda", Code = "BM" });
country.Add(new Countries { Name = "Canada", Code = "CA" });
country.Add(new Countries { Name = "Cameroon", Code = "CM" });
country.Add(new Countries { Name = "Denmark", Code = "DK" });
country.Add(new Countries { Name = "France", Code = "FR" });
return country;
}
}
public class HomeController : Controller
{
public ActionResult Index()
{
Countries model = new Countries();
ViewBag.data = new Countries().CountriesList();
model.CountyId = new string[] { "Cameroon" , "Denmark"};
return View(model);
}
[HttpPost]
public ActionResult Index(Countries model)
{
ViewBag.data = new Countries().CountriesList();
return View(model);
}
|
Hi Gayathri,
thank you for support.
The proposed solution also does not work.
I'll attach a sample solution to show you the error.
@(
Html.EJS().Grid<Test>("GridProdotti").ActionBegin("onActionBegin").DataSource(dataManager => { dataManager.Json(((IEnumerable<GridData>)ViewBag.dataSource).ToArray()).InsertUrl("/Home/Insert").Adaptor("RemoteSaveAdaptor"); }).Render()
) |
public ActionResult Insert(CRUDModel1<GridData> dm)
{
// Here the inserted data needs to be updated in the back end data and returned back to the Grid
new GridData().DataList().Insert(0, dm.value);
return Json(dm.value);
} |
// Grid’s actionBegin event handler
function onActionBegin(args) {
if (args.requestType === "save") {
var listInstance = args.form.querySelector("#CountyId").ej2_instances[0];
var itemValues = "";
listInstance.getSelectedItems().forEach(ele => {
if (itemValues === "")
itemValues = ele.innerText;
else
itemValues = itemValues + ", " + ele.innerText;
});
// The list control selected text is retrieved as single string and set to its corresponding data field
args.data["CountyId"] = itemValues;
}
} |
Hi Aravinthan,
Thank you for support.
Perfect!
Nice solution.
Hi Aravinthan,
Unfortunately the proposed solution does not meet the requirements, I can not use a crudmodel1 class, I am obliged to use the model I created, as in example attached is Test class.
For this I need to receive an array of guid, also because I do not know how to select the values of the listbox based on those returned from the database.
function onActionBegin(args) {
if (args.requestType === "save") {
var listInstance = args.form.querySelector("#CountyId").ej2_instances[0];
args.data["CountyId"] = listInstance.value;
}
} |
public ActionResult Insert(CRUDModel1<Test> dm)
{
// Here you can access the GUID values from ‘dm.value’
List<Test> model = new List<Test>();
model.Add(dm.value);
return Json(dm.value);
}
public class CRUDModel1<T>: Test
{
public string action { get; set; }
public string keyColumn { get; set; }
public int key { get; set; }
public T value { get; set; }
}
public class Test
{
public Guid[] CountyId { get; set; }
public string t { get; set; }
public int Id { get; set; }
} |
|
Hi Aravinthan,
Thank you for support.
Perfect!
Now proposed solution meet the requirements .
Nice job.