Reputation: 2295
I am trying to remove the validation for this combobox in the Custom Editor Template:
...
@{
ViewContext.FormContext = new FormContext();
}
<div data-container-for="ClientId" class="k-edit-field">
@(Html.Kendo().ComboBoxFor(model => model.ClientId)
.HtmlAttributes(new { data_bind = "value:ClientId", id = "ClientId", data_val = false })
.Name("ClientId")
.DataTextField("Text")
.DataValueField("Value")
.DataSource(source => { source.Read(read => { read.Action("GetClientsList", "Scheduler"); }).ServerFiltering(true); })
.Events(e =>
{
e.Select("onSelect");
})
.HtmlAttributes(new { style = "width:100%;" }))
</div>
@{
ViewContext.FormContext = null;
}
...
Tried to remove the validation in the model using:
[AllowAnyValue]
public int? ClientId { get; set; }
public class AllowAnyValueAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
// Always return true to allow any value
return true;
}
}
Trying to add a new text in the combobox input, for example a name, I still get this Kendo error message:
`The field ClientId must be a number.`
Upvotes: 0
Views: 41
Reputation: 11
I am not very familiar with validating Kendo controls, but it appears to me that you are specifying the combobox for an entity with fields "Text" and "Value", whereas the entity you are binding is a simple nullable int named "ClientId".
Add a class CbBoxValue like this:
public class CbBoxValue
{
[AllowAnyValue]
public int? Value { get; set; }
public string Text { get; set; }
public CbBoxValue ( int? ClientId )
{
Value = ClientId;
Text = ClientId?.ToString() ?? "";
}
}
And then pass CbBoxValue(ClientId) to the combobox instead of directly passing ClientId.
Note: I have not tested this and as I said I am not very familiar with the matter, but this seems only logical to me.
Upvotes: 0