This is a migrated thread and some comments may be shown as answers.

[Solved] How to set RadComboBox initial value in MVC and using EnableLoadOnDemand="true"?

1 Answer 53 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tijana
Top achievements
Rank 1
Tijana asked on 10 Dec 2009, 11:35 AM
Hello, I need help with RadComboBox in MVC.

I have a list of data which are shown in RadComboBox. When I open EDIT page, I want do see value that was saved (set) before.
This is my html code:

 <telerik:RadComboBox runat="server" ID="SelectionId" EnableLoadOnDemand="true" AllowCustomText="true" ShowMoreResultsBox="true" EmptyMessage="Type here ..." Height="100px"
          MarkFirstMatch="True">
          <WebServiceSettings Path="~/Mailing/" Method="LoadItemsSelections" />
        </telerik:RadComboBox>

So, I am using Mailing controller (it is MVC) and I call method LoadItemsSelections when user clicks on RadComboBox.
Initialy, when no item is selected, "Type here ..." text is displayed in RadComboBox.
When I select item and save it, by calling method LoadItemsSelections in Mailing controller, I save that selectionId.
When I edit form, "Type here ..." text is displayed againg, since I can't set value before user clicks on the control. Data is loaded on demand.

Here is LoadItemsSelections code from Mailing controller
[JsonParamFilterAttribute(Parameter = "context", TargetType = typeof(RadComboBoxContext))]
    public JsonResult LoadItemsSelections(RadComboBoxContext context)
    {
 return Json(new { d = result });
    }

So, the Question is:
Is there anyway to set that saved Model.SelectionId in RadComboBox on edit?
Or, maybe solution could be to load that list of items on RadComboBox load if Model.SelectionId is set to some value?

How can I do that? What is the best solution?

I need you answer as soon as possible,
Thanks!
Tijana

P.S. By the way, if anyone have problems with MVC and RadComboBox - calling method from controller, this could be solution:
<WebServiceSettings Path="~/Mailing/" Method="LoadItemsSelections" />
I had error "the server method 'LoadItemsSelections' failed" because the code was:
<WebServiceSettings Path="Mailing" Method="LoadItemsSelections" />, but since it is not webservice, but MVC,
solution is to set Path to "~/Mailing/"!!!!




1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 10 Dec 2009, 01:47 PM
Hello Tijana,

You can use the following JavaScript snippet to set the RadComboBox text:

$find('SelectionId').set_text("<%= Model.SectionId %>");

All the best,
Alex
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Tijana
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or