I've posted my question in a wrong forum,
So I reposted the quesiton again here.
Scenario:
I am trying to enable and disable CheckBoxGroup items,
and it dependes on whether if the categories of the item has values.
For example, If there are two categorie, which are animals and fruits.
If I recieved no datas of fruits, I'll disabled the CheckBoxGroup item "fruits".
What I've tried so far
I search through documents and found this tutorial of the BindTo() method,
However, I got an error message saying "Cannot convert from System.Collections.Generic.List<MyCheckBoxItemModel> to string []
Questions
1. According to the method, how can I convert List<model> to string[] in my .cshtml ?
2. (Extension Question) In the tutorial, I'm awared that in the "InputGroupItemModel" there was a "Enabled" attribute.
Is it mean that if passed it to the front end and attached it with the BindTo() method, the CheckBoxGroup will automatically enable or disable the checkbox item?
(I'll show my code below)
Code
CheckBoxItemDto.cs
public class CheckBoxItemDto
{
//public IDictionary<string, object> HtmlAttributes { get; set; }
//public string CssClass { get; set; }
public bool? Enabled { get; set; }
//public bool? Encoded { get; set; }
public string Label { get; set; }
public string Value { get; set; }
}
CheckBoxItemViewModel.cs
public class CheckBoxItemViewModel
{
public List<CheckBoxItemDto> Items { get; set; }
public string[] CheckBoxGroupValue { get; set; }
}
MyViewModel.cs
public class EqInstsDataViewModel
{
public IEnumerable<MyOtherViewModel> MyOtherViewModel { get; set; }
public CheckBoxItemViewModel CheckBoxItemViewModel { get; set; }
}
Controller
public IActionResult GetChartPartialView()
{
try
{
List<CheckBoxItemDto> checkBoxItemDto = GetCheckBoxItem(); //Get CheckBox Items
CheckBoxItemViewModel checkBoxItem = new CheckBoxItemViewModel() { Items = checkBoxItemDto };
MyViewModel myViewModel = new MyViewModel() { Items = checkBoxItem }
return PartialView("~/Views/Shared/_MyPartialView.cshtml", myViewModel);
}
catch (Exception ex)
{
return Json(ex.Message);
}
}
public List<CheckBoxItem> GetCheckBoxItem()
{
try
{
#region CheckBoxItems
var itemsList = new List<CheckBoxItemDto>()
{
new CheckBoxItemDto()
{
Label = "Animals",
Value = "1",
Enabled = true
},
new CheckBoxItemDto()
{
Label = "Friuts",
Value = "2",
Enabled = false
} ,
};
#endregion
return itemList;
}
catch(Exception)
{
throw;
}
}
_MyPartialView.cshtml
@(Html.Kendo().CheckBoxGroup()
.Name("MyCheckBox")
.BindTo(Model.CheckBoxItemViewModel.Items) //Cannot convert from List<CheckBoxItemDto> to string[]
.Value(Model.CheckBoxItemViewModel.CheckBoxGroupValue)
.Layout("horizontal")
)
Hello,
I am using JQuery validation to validate a form containing many controls in addition to 2 kendo controls. The checkboxgroup and a radiogroup.
After updating the project to 2022.1.119 from 2021.1.330 the validation on the form gets the following error:
Upon inspecting the error (this is inside of the jquery.validate.js file) i see that for only the two kendo controls, the $(element).rules() is evaluating to undefined and then when line 754 runs it errors because "rules" is nothing
My question is what changed to cause this? I only see very small tweaks to the HTML output of the core wrapped controls, im not seeing anything that would cause rules() to evaluate undefined.
Here is my JS for the validation setup:
var validateValue = $("#frmAdditem").validate({
errorClass: "error fail-alert",
validClass: "valid success-alert",
errorPlacement: function (error, element) {
//Custom position: first name
if ($(element).attr("name") == "chkAIWork") {
$("#lblChkAIWork").text(error[0].innerText);
}
else if ($(element).attr("name") == "rdoMatchType") {
$("#lblRdoMatchType").text(error[0].innerText);
}
else if ($(element).attr("name") == "dpAIReleaseBy") {
$("#lbldpAIReleaseBy").text(error[0].innerText);
}
else {
error.insertAfter(element);
}
},
rules: {
txtAIPart: {
required: true,
minlength: 2,
maxlength: 100
},
txtAIRev: {
required: true,
maxlength: 10
},
chkAIWork: {
required: {
depends: function (element) {
return !$("#chkAIWork").getKendoCheckBoxGroup().value() == '';
}
}
},
rdoMatchType: {
required: {
depends: function (element) {
return $("#rdoMatchType").getKendoRadioGroup().value() == undefined;
}
}
},
ddlAIProjectType: {
required: true
},
txtAIProj: {
required: true,
maxlength: 30
},
dpAIReleaseBy: {
required: true
}
},
messages: {
txtAIPart: {
required: "Part is required",
minlength: "Part should be at least 3 characters"
},
txtAIRev: {
required: "Rev is required"
},
chkAIWork: {
required: "Work selection is required"
},
rdoMatchType: {
required: "Match type is required"
},
ddlAIProjectType: {
required: "Type is required"
},
txtAIProj: {
required: "Project name required"
},
dpAIReleaseBy: {
required: "Release by required"
}
},
success: function (label, element) {
if ($(element).attr("name") == "chkAIWork") {
$("#lblChkAIWork").text('');
}
else if ($(element).attr("name") == "rdoMatchType") {
$("#lblRdoMatchType").text('');
}
else if ($(element).attr("name") == "ddlAIProjectType") {
$("#lblddlAIProjectType").text('');
}
else if ($(element).attr("name") == "dpAIReleaseBy") {
$("#lbldpAIReleaseBy").text('');
}
}
});
I'm aware there is a kendo validate but have never used it because JQuery validate was working fine before the upgrade
Can anyone help with this?
Thanks
Hello,
I have followed this help article, how to bind CheckBoxGroup to model on razor page. This article does not show how to get selected values back on post.
https://docs.telerik.com/aspnet-core/html-helpers/editors/checkboxgroup/razor-page
OnPost CheckBoxGroupModel models that is bind property, it's CheckBoxGroupValue property stays null when posted back. Only way to get values back is to read them from Request.Forms["checkboxgroup"].