I am evaluating the kendo controls for purchase and I am having trouble setting a kendo dropdown to readonly in mvc 4 using the razor view engine. I keep getting the error
0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'readonly'
My solution is a little more complex but basically I have the below code with a bunch of stuff cut out. Everything works fine until i want to set the dropdown to read only on page load in one of my cases. It seems like I am following the documentation but i can't see to figure out what is wrong. I've spent a good few hours on this and am out of tricks. I've got access to the dropdown for click events that i set on buttons and such but not during the $(document).ready.
I feel like something in .readonly() is using something not in my jquery but that is only a wild guess.
Thanks in a advance
<script>
//.readonly()doesn't work
$(document).ready(function () {
var something = $("#ProvinceRegion").data("kendoDropDownList");
something.readonly();
//note: something.enable(false); works here just readonly() doesn't
});
//notice I can set .enabled on this function below
function ClearCustomerClick() {
//all the below work
var dropdownlist = $("#CustomerName").data("kendoDropDownList")
dropdownlist.select(0);
var billContactList = $("#BillingContact").data("kendoDropDownList")
billContactList.enable(false);
var billSiteList = $("#BillSite").data("kendoDropDownList")
billSiteList.enable(false);
}
</script>
and then my dropdown list is below
@using (Html.BeginForm("ProjectSetupDetails", "Setup", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@(Html.Kendo().DropDownList()
.Name("ProvinceRegion")
.OptionLabel("Pick a region...")
.BindTo(Model.RegionList))
}
15 Answers, 1 is accepted
The readonly functionality is available since Q1 2013 (2013.1.319). Before this release the widgets did not have support for readonly. Please verify that you are using the latest official release of Kendo UI.
Check this jsBin demo, which shows how to use readonly method.
Georgi Krustev
the Telerik team

I am currently using the 2012.3.1114.340 for Kendo.MVC dll. I will look into updating the to the latest version to see if I can get readonly to work.
**Update: Georgi's solution worked

Is there any way to set a kendo dropdown to readonly when using the mvc razor html helpers to generate the control?
All the threads I have found only show examples doing it with the javascript function, but surely there must be a way to do this with razor in c#.
You can use the following approach to achieve this requirement:
.HtmlAttributes(new { style = "width:50%", @readonly = "readonly" })
I hope this will prove helpful.
Regards,
Eyup
Telerik by Progress
https://stackoverflow.com/questions/34889537/conditional-html-attribute-with-html-helper

You can use the following approach to achieve this requirement:
.HtmlAttributes(new { style = "width:50%", @readonly = "readonly" })
I hope this will prove helpful.
Regards,
Eyup
Telerik by Progress
[/quote]
that only works on the first dropdown in a series of cascaded dropdowns. Why is that? The readonly attribute has absolutely no effect on the 2nd and subsequent dropdowns!

Kendo provides built-in cascading combo functionality, where the dependent combos are kept in disabled mode until selection is made:
https://demos.telerik.com/kendo-ui/combobox/cascadingcombobox
Alternatively, you can use the $(document).ready() event to access all combos using jQuery and call the readonly method to them:
https://docs.telerik.com/kendo-ui/api/javascript/ui/combobox/methods/readonly
Regards,
Eyup
Progress Telerik


You can use the following approach to disable multiple dropdowns/combos on the page. Could you check the disableDropDowns() method and let me know if this will be suitable for your scenario?
https://dojo.telerik.com/UNinikim/9
Regards,
Eyup
Progress Telerik

I'm glad that you've managed to find a specific solution for your scenario.
If you want further suggestions on this matter, feel free to send us a modified dojo sample resembling your own configuration so we can provide more precise and accurate solutions.
Alternatively, you can also open a formal support ticket to send us an archive with your project.
Regards,
Eyup
Progress Telerik

How can I use @readonly attribute conditionally?
Based on some logic it should add readonly
.HtmlAttributes(new { style = "width:50%", @readonly = "readonly" })
else "not readonly" -
.HtmlAttributes(new { style = "width:50%" })
How can I achieve it
Hi,
You can try using conditional attributes or custom javascript to achieve this requirement:
- https://www.davidhayden.me/blog/conditional-attributes-in-razor-view-engine-and-asp.net-mvc-4
- https://stackoverflow.com/questions/9399531/asp-net-mvc-razor-conditional-attribute-in-html
I hope this helps.
Regards,
Eyup
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.

Hi Aggeliki,
This seems a nice idea - you can log it in our Public Feedback Portal so it can gather better traction: