Telerik Forums
UI for ASP.NET MVC Forum
5 answers
1.0K+ views
See code example below....  I currently have two dropdown lists that are linked together as cascading dropdowns.  In the case where the second dropdown (that is dependant ont he first dropdown) only gets one value populated to it I would like it to be autoselected instead of making the user select the single value that gets placed in that dropdown.

However, if the second dropdown gets populated with more than one value, then I would like the placeholder text to show as it does today.

Any ideas on how to best go about achieving this?  FYI, this is currently set up so that the second dropdown list is disabled until a value is selected from the first.  I figured this out but can't figure out the autoselecting of the second dropdown if only one value.

Thanks,
Jason





<!-- START ACTIVITY TYPE -->
<div class="span3">
    <span class="activity-label">Activity Type</span>
    <div class="row-fluid">
        @(Html.Kendo().DropDownList()
            .Name(String.Format("MCActivityTypeId{0}", i))
            .OptionLabel("Select Activity Type...")
            .HtmlAttributes(new { @class = "span12 case_mc_activityTypeId" })
            .DataValueField("WorkflowQueueActivityMapId")
            .DataTextField("ActivityName")
            .DataSource(ds =>
            {
                ds.Read(r => r.Action("ActivityTypeData", "Workdriver", new { Id = act.WorkflowQueueId }));
            }
            )
            .Enable(showChargeIntegrityEditAddNew && act.IsDataEntry)
        )
    </div>
</div>
<!-- END ACTIVITY TYPE -->

<!-- START ACTIVITY STATUS -->
<div class="span3">
    <span class="activity-label">Activity Status</span>
    <div class="row-fluid">
        @(Html.Kendo().DropDownList()
            .Name(String.Format("MCActivityStatus{0}", i))
            .OptionLabel("Select Activity Status...")
            .HtmlAttributes(new { @class = "span12 case_mc_activityStatusId" })
            .DataValueField("WorkflowQueueActivityStatusMapId")
            .DataTextField("ActivityStatusName")
            .DataSource(ds =>
            {
                ds.Read(r =>
                {
                    r.Action("ActivityStatusData", "Workdriver")
                        .Data(@<text>function() { return { id: $('#MCActivityTypeId@(i)').val() }; }</text>);
                }).ServerFiltering(true);
            }
            )
            .Enable(false)
            .AutoBind(false)
            .CascadeFrom(String.Format("MCActivityTypeId{0}", i))
        )
    </div>
</div>
<!-- END ACTIVITY STATUS -->
Dimiter Madjarov
Telerik team
 answered on 14 Feb 2014
7 answers
1.2K+ views

Hi, I need to send in a bunch of form values to the create method (add new button) on the grid.
For edit, I used like this and it works fine.
grid call:
.Read(read => read.Action("Read_FinesByMLS", "FinesHistoryByMLS").Data("ParameterData"))

js function:
function ParameterData() {
         alert("para=" + $("#MLSNumber").val());
        return {
              MLSNumber: $("#MLSNumber").val()
        }
}

controller function:
public ActionResult Read_FinesByMLS([DataSourceRequest] DataSourceRequest request, string MLSNumber)
{
              using (var context = new MATRIXEntities_Connection ())
              {
                       IQueryable<FineHistory> finebymls = context.FineHistories;
                       if (MLSNumber != null)
                       {
                                  finebymls = finebymls.Where(f => f.MLSNumber == MLSNumber); }                       
                               DataSourceResult result = finebymls.ToDataSourceResult(request, f => new                    FineHistoryViewModel
                         {
                                   FineHistoryId = f.FineHistoryId ,
                                   FineCode = f.FineCode,
                             });
                            return Json(result);
                     }
}


When I tried to do same for create, I am not getting any value for the parameter in the controller function. MLSNumber param is coming null. Any help is appreciated. Thanks

here is my create action call.
.Create(create => create.Action("Create_FinesByMLS", "FinesHistoryByMLS").Data("ParameterData"))

Its the same function call as above for edit function.

Controller function.

public ActionResult Create_FinesByMLS([DataSourceRequest] DataSourceRequest request,  string MLSNumber)
      {
 
          using (var objFines_Context = new MATRIXEntities_Connection())
          {
 
              */
              //objFines_Context.usp_InsertFineHistory("211131297", "479", 4790, "713779DAF4844A", "239024", "281530", "kmantrip", "M");
              //objFines_Context.SaveChanges();
          }
          return View();
      }

the parameter is

Dimiter Madjarov
Telerik team
 answered on 14 Feb 2014
2 answers
346 views
Hi All,

Could someone please tell me what I'm doing wrong here.
All I want to do is display a checkbox if Resend is true?

columns.Bound(p => p.Id).ClientTemplate("#=Resend ? '' : '<input id=\"resend\" value='#=Id#' class=\"chkbxq\" type=\"checkbox\" />' #").Title("test");


Tim
Top achievements
Rank 1
 answered on 13 Feb 2014
2 answers
564 views
This may be a dumb question, so please excuse me if it is.

I'm looking into starting a new web application project. I've made a web app before using ASP .Net AJAX and the Component Art controls.  If I go with the AJAX framework, I'll most certainly use Telerik's controls; I've had a great experience with Telerik's support for their WPF controls.  However, I am also considering using ASP .Net MVC, but I noticed that there are far fewer controls available for that than under AJAX.

My question: Is the smaller selection of controls available for the MVC framework just a matter of the AJAX framework being around longer or is there a technical limitation?

Thanks.
Don
Top achievements
Rank 1
 answered on 12 Feb 2014
10 answers
270 views
Hello there,

I am trying the simple example on the site (Ajax Grid Biding and Editing) and the Grid isn't showing me any data. I tried the server binding and it works. Below is my code.

Razor:
@(Html.Kendo().Grid<KendoTest2.Models.DocumentType>()
      .Name("grid")
      .DataSource(dataSource => dataSource // Configure the grid data source
          .Ajax() // Specify that ajax binding is used
          .Read(read => read.Action("Products_Read", "Home")) // Set the action method which will return the data in JSON format
       )
      .Columns(columns =>
      {
          // Create a column bound to the ProductID property
          columns.Bound(product => product.Id);
          // Create a column bound to the ProductName property
          columns.Bound(product => product.Name);
          // Create a column bound to the UnitsInStock property
        
      })
      .Pageable() // Enable paging
      .Sortable() // Enable sorting
)
Controller:

public ActionResult Products_Read([DataSourceRequest]DataSourceRequest request)
        {
            using (var northwind = new MMCC_DocumentManagementEntities())
            {
                IQueryable<DocumentType> products = northwind.DocumentTypes;
                DataSourceResult result = products.ToDataSourceResult(request);
                return Json(result);
            }
        }
It's the simple example on the site, adapted on my model. That's all. Not showing data. I checked and the Json(result) returns data. What could it be the problem?
Vladimir Iliev
Telerik team
 answered on 12 Feb 2014
2 answers
1.0K+ views
Hi,

I want to display an enum in my dropdown list column of Kendo Grid.
I get an success till binding the enum in a dropdown list and displaying it to the Grid. But however it displays as a textbox instead of a dropdown list when I add/edit an item in edit popup. It shows proper dropdown list in InLine editing mode.
One more issue is it displays enum values (1, 2 or 3) instead of enum texts (Red, Amber or Green) in a grid.

My grid column is:
columns.Bound(r => r.RagStatus).EditorTemplateName("RAGStatus");
 
Enum is:
public enum RAGStatus
{
           Red = 1,
            Amber = 2,
            Green = 3,
}
 
public static List<SelectListItem> EnumToSelectList(Type enumType)
{
            return Enum
              .GetValues(enumType)
              .Cast<int>()
              .Select(i => new SelectListItem
                {
                    Value = i.ToString(),
                    Text = Enum.GetName(enumType, i),
                }
              )
              .ToList();
}
 
Enum template is:
@model int
@(
 Html.Kendo().DropDownListFor(m => m)
        .BindTo(EnumToSelectList(typeof(RAGStatus)).ToList())
        .OptionLabel(optionLabel: "Please Select")
        .SelectedIndex(0)
)
Please help.

Thanks,
Nirav


Shawn
Top achievements
Rank 2
 answered on 11 Feb 2014
3 answers
123 views
Hi,
I have a question about the design of a Grid. I attach a image that show an idea of how I need the grid.
Please, I wonder if this is possible. 

Thanks.
Petur Subev
Telerik team
 answered on 11 Feb 2014
5 answers
88 views
anyone know if the autocomplete control is capable of grouping?
Petur Subev
Telerik team
 answered on 11 Feb 2014
1 answer
95 views
So I've been reading, that AutoComplete does not have a value property. Is this true? If so, why not. I was forced to use a multicomplete field and set the MinValue to 1
in order to get the job done. Also, can anyone explain the difference between .Template and .ClientTemplate
Alexander Popov
Telerik team
 answered on 11 Feb 2014
1 answer
433 views
I am trying to do the following:
  1. Use a Kendo UI Grid
  2. Have columns that have dropdowns for editors
  3. Have a re-usable method to implement those dropdowns
  4. Send the values from the grid to the server when the form posts

Here's what I've done so far:
I have the grid showing on my page and editable.  I am able to send the values from the grid to the server with the form post (using a method similar to the one shown here: http://www.telerik.com/support/code-library/submit-form-containing-grid-along-with-other-input-elements)
I have looked at the custom editor examples here (http://demos.telerik.com/kendo-ui/web/grid/editing-custom.html) and here (http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/editor-templates) but this method involves creating a partial view for each dropdown.  I would prefer not to have to copy/paste/edit this code every time I need a new dropdown.  I think there should be a way to create a re-usable partial view that can perform this function.  Along these lines, I have created a small view model and partial view like what is mentioned here (https://stackoverflow.com/questions/11498215/asp-net-mvc-built-in-support-for-dropdownlist-editor-template).

Current status:
The dropdown appears in my grid as expected, and I can select a value.  I don't know how to get the text and value of the selected item so I can include them in the ClientTemplate, however.

My grid looks like this:
@(Html.Kendo().Grid<AccountManagement.Business.ViewModels.Areas.DM.RehireDocumentSettingViewModel>()
                    .Name("DocumentSettings")
                    .Columns(columns => {
                            /*
                            columns.Bound(ds => ds.FormID)
                                .ClientTemplate("#= FormID #" +
                                    "<input type='hidden' name='DocumentSettings[#= index(data)#].FormID' value='#= FormID #' />"
                                );
                            */
                            columns.Bound(ds => ds.FormsViewModel)
                                .ClientTemplate("#= 'test' #" +
                                    "<input type='hidden' name='DocumentSettings[#= index(data)#].FormID' value='#:data.Value #' />"
                                );
                            columns.Bound(ds => ds.DocumentDateTypeName)
                                .ClientTemplate("#= DocumentDateTypeName #" +
                                    "<input type='hidden' name='DocumentSettings[#= index(data)#].DocumentDateTypeName' value='#= DocumentDateTypeName #' />"
                                );
                            columns.Bound(ds => ds.RemoveIfOlderThanDays)
                                .ClientTemplate("#= RemoveIfOlderThanDays #" +
                                    "<input type='hidden' name='DocumentSettings[#= index(data)#].RemoveIfOlderThanDays' value='#= RemoveIfOlderThanDays #' />"
                                );
                            columns.Command(command => command.Destroy());
                        }
                    )
                    .ToolBar(toolbar => {
                        toolbar.Create();
                    })
                    .Navigatable()
                    .Sortable()
                    .Scrollable()
                    .Editable(editable => editable.Mode(GridEditMode.InCell))
                    .DataSource(dataSource => dataSource
                        .Ajax()
                        .Batch(true)
                        .ServerOperation(false)
                        .Events(events => events.Error("error_handler"))
                        .Model(model => model.Id(ds => ds.FormID))
                        .Read("RehireDocumentSetting_Editing_Read", "RehireSetup")
                    )
                )

The small viewmodel for my dropdown partial editor looks like this:
public class DropDownViewModel
    {
        public string SelectedID { get; set; }
        public IEnumerable<SelectListItem> Items { get; set; }
    }

My partial view looks for the dropdown editor looks like this:
@model AccountManagement.Business.ViewModels.Areas.DM.DropDownViewModel
 
@(Html.Kendo().DropDownListFor(m => m)
    .DataValueField("Value")
    .DataTextField("Text")
    .BindTo(new SelectList(Model.Items, "Value", "Text", Model.SelectedID))
    .Value("SelectedID")
)

So my question is: is there a way to fix my ClientTemplate for the FormsViewModel column so that it displays the text of the selected item when not being edited (instead of 'text' as it does now) and submits the ID of the selected item to the server?  Alternatively, is there another way to do this that meets items 1-4 at the top of this post?

Any ideas are appreciated.

Thanks,
Brian




Petur Subev
Telerik team
 answered on 11 Feb 2014
Narrow your results
Selected tags
Tags
Grid
General Discussions
Scheduler
DropDownList
Chart
Editor
TreeView
DatePicker
Upload
ComboBox
MultiSelect
ListView
Window
TabStrip
Menu
Installer and VS Extensions
Spreadsheet
AutoComplete
TreeList
Gantt
PanelBar
NumericTextBox
Filter
ToolTip
Map
Diagram
Button
PivotGrid
Form
ListBox
Splitter
Application
FileManager
Sortable
Calendar
View
MaskedTextBox
PDFViewer
TextBox
Toolbar
MultiColumnComboBox
Dialog
DropDownTree
Checkbox
Slider
Switch
Notification
ListView (Mobile)
Pager
Accessibility
ColorPicker
DateRangePicker
Wizard
Security
Styling
Chat
MediaPlayer
TileLayout
DateInput
Drawer
SplitView
Barcode
ButtonGroup (Mobile)
Drawer (Mobile)
ImageEditor
RadioGroup
Sparkline
Stepper
TabStrip (Mobile)
GridLayout
Template
Badge
LinearGauge
ModalView
ResponsivePanel
TextArea
Breadcrumb
ExpansionPanel
Rating
ScrollView
ButtonGroup
CheckBoxGroup
NavBar
ProgressBar
QRCode
RadioButton
Scroller
Timeline
TreeMap
TaskBoard
OrgChart
Captcha
ActionSheet
Signature
DateTimePicker
AppBar
BottomNavigation
Card
FloatingActionButton
Licensing
Localization
MultiViewCalendar
PopOver (Mobile)
Ripple
ScrollView (Mobile)
Switch (Mobile)
PivotGridV2
FlatColorPicker
ColorPalette
DropDownButton
AIPrompt
PropertyGrid
ActionSheet (Mobile)
BulletGraph
Button (Mobile)
Collapsible
Loader
CircularGauge
SkeletonContainer
Popover
HeatMap
Avatar
ColorGradient
CircularProgressBar
SplitButton
StackLayout
TimeDurationPicker
Chip
ChipList
DockManager
ToggleButton
Sankey
OTPInput
ChartWizard
SpeechToTextButton
InlineAIPrompt
TimePicker
StockChart
RadialGauge
ContextMenu
ArcGauge
AICodingAssistant
+? more
Top users last month
Rob
Top achievements
Rank 3
Bronze
Iron
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Bronze
Iron
Iron
Sergii
Top achievements
Rank 1
Iron
Iron
Dedalus
Top achievements
Rank 1
Iron
Iron
Lan
Top achievements
Rank 1
Iron
Doug
Top achievements
Rank 1
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?