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

[Solved] MVC2 control access issue

2 Answers 85 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dayana Maliyakal
Top achievements
Rank 1
Dayana Maliyakal asked on 20 Nov 2013, 08:52 AM
Hi Telerik team,

  I am using telerik mvc2 in asp.net c#.I view I am using the following combobox control

View

<%

 

= Html.Telerik().ComboBoxFor(model =>model.StatusID)

 

.BindTo(model.

 

test.GetStatus())

 

%>

Controller

Here I want to access the above control.How to write code here?
I needs to set enable/disable property here.I think in aspx page we can write it as radcombobox1.enable=false.I need the same here

With reagards
Dayana

2 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 22 Nov 2013, 03:31 PM
Hello,

You can use the Enable method to specify whether the combobox should be enabled or not. The controls cannot be accessed from the controller. You should pass a parameter from the action to the view that indicates whether the control should be enabled or not:
//action method
ViewData["enabled"] = false;
Html.Telerik().ComboBoxFor(model =>model.StatusID)
    .Enable((bool)ViewData["enabled"])


Regards,
Daniel
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dayana Maliyakal
Top achievements
Rank 1
answered on 28 Nov 2013, 11:56 AM
Hi Telerik Team,

Thanks for the reply.

How to pass selected text of combobox from view to controller?

View

<%

 

= Html.Telerik().ComboBoxFor(model => model.UserID).Name("rdcmbRequestedBy")

 

.Enable(

 

false)

 

.BindTo(Model

 

.GetVal())

 

%>

Model

public

 

 

static SelectList GetVal()

 

{

 

 

User myUser = new User();

 

 

 

DataTable dtRequested = myUser.GetUser(true);

 

 

 

var x = (from DataRow dr in dtRequested.AsEnumerable()

 

 

 

select new SelectListItem()

 

{

Value = dr.Field<

 

int>("UserID").ToString(),

 

Text = dr.Field<

 

string>("ListDisplayName")

 

}).ToList();

 

 

var list = dtRequested.AsEnumerable().Select(s => new { UserID = s.Field<int>("UserID"), ListDisplayName = s.Field<string>("ListDisplayName") }).ToList();

 

 

 

return new SelectList(list, "UserID", "ListDisplayName");

 

}


I want to get ListDisplayName in my controller

With regards
Dayana

Tags
ComboBox
Asked by
Dayana Maliyakal
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Dayana Maliyakal
Top achievements
Rank 1
Share this question
or