Telerik Forums
UI for ASP.NET MVC Forum
1 answer
776 views
Hello,

I'm trying to set the value of the cascading dropdownlist, i want to set the value that the model have in the second dropdownlist. The value seems to be set, but only after i first click on the second dropdownlist then i get the right "name" in the list. Anything i'm doing wrong?
   <script>
                function contractorChanged() {
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("GetContactPersons", "Permission")',
                        data: {
                            id: $("#ContractorId").val()
                        },
                        cache: false,
                        success: function (data) {
                            $("#ContractorPersonId").data("kendoDropDownList").setDataSource(data);
                       $("#ContractorPersonId").data("kendoDropDownList").value('@Model.ContractorPersonId');
 
                        }
                    });
                }
 
            </script>           
 
@(Html.Kendo().DropDownListFor(model => model.ContractorId)
              .HtmlAttributes(new { style = "width:100%; margin-bottom: 8px;" })
              .OptionLabel("Välj företag")
              .DataTextField("Name")
              .DataValueField("Id")
              .Events(e => e.DataBound("contractorChanged"))
              .DataSource(source =>
              {
                  source.Read(read => { read.Action("GetConstructors", "Permission"); });
              }))
 
            @(Html.Kendo().DropDownListFor(model => model.ContractorPersonId)
              .HtmlAttributes(new { style = "width:100%" })
              .OptionLabel("Välj kontaktperson")
              .DataTextField("FullName")
              .DataValueField("Id")
              .Enable(false)
              .AutoBind(false)
              .CascadeFrom("ContractorId")
            )


Georgi Krustev
Telerik team
 answered on 08 May 2014
6 answers
254 views
Hi,

I have a splitter with a treeview in one vertical pane on the left.  When a user clicks an item in the treeview, I would like to load items in horizontal panes in the center.  Is this possible?
thank you,
Alex Gyoshev
Telerik team
 answered on 08 May 2014
1 answer
93 views
I am trying to use the drag and drop framework, but cant seem to get any events on the drop are, such as dragenter.

am I missing something? thanks

​
<div class="draggable">
    drag me
</div>
<div  id="test-area">
    <h2>
        Test area
    </h2>
    <h2>
        Test area
    </h2>
    <h2>
        Test area
    </h2>
    <h2>
        Test area
    </h2>
    <h2>
        Test area
    </h2>
    <h2>
        Test area
    </h2>
    <h2>
        Test area
    </h2>
</div>
 
<script>
 
    $(document).ready(function () {
    
        $("#test-area").kendoDropTargetArea({
            dragenter: DragAndDrop.dropTargetOnDragEnter,
            dragleave: DragAndDrop.dropTargetOnDragLeave,
            drop: DragAndDrop.dropTargetOnDrop
        });
 
        $(".draggable").kendoDraggable({
            hint: function () {
                return $(".draggable").clone();
            },
            dragstart: DragAndDrop.draggableOnDragStart,
            dragend: DragAndDrop.draggableOnDragEnd
        });
 
 
    });
 
 
    var DragAndDrop = {
        draggableOnDragStart: function (e) {
            $(".draggable").addClass("hollow");
            $(".draggable").css("cursor", "no-drop");
            e.currentTarget.hide();
 
        },
        draggableOnDragEnd: function (e) {
            e.currentTarget.show();
 
        },
        dropTargetOnDrop: function () {
            alert(2);
 
        },
        dropTargetOnDragEnter: function () {
            alert(1);
            $(".draggable").css("cursor", "wait");
 
        },
        dropTargetOnDragLeave: function () {
            alert(3);
 
        }
    };
 
 
</script>
Alan Mosley
Top achievements
Rank 1
 answered on 08 May 2014
0 answers
128 views
Anyone know the best way to get my rows as a comma separated string?  I got it to work one way, but I think it returns too much data. I built an iqueryable sequence with a sub query. The sub query are the results want to transpose. Then I selected from the returned object and used string.join().  However, the first query repeats my main records and will waste bandwidth. For example (pseudo code):

Table1.Column1 Table1.Column2
1 John Smith

Table2.Column1 Table2.Column2
1 Blue
1 Green

var a = (from Table1 in context
select new Model {
Name = Table1.Column2,
Color = context.table2.where(x => x.Column1 == Table1.Column1).Select(x => x.Column2)
});

When executed a returns multiple names. e.g.

John Smith Blue
John Smith Green

the following does delimit it properly, however i'm concerned of the wasted bandwidth caused by the previous query.  

var b = a.Select(q => new Model
{Name = a.Name,
Color = string.join(",",a.Color)
});

The final result will be like this:

John Smith Blue, Green.

Should I make two connections to the sql server instead? Should I send an array of my IDs to sql or should I loop thru the first results then get the colors? Any suggestions would be great!  I prefer to keep using the DataSourceRequest object, rather than a custom stored procedure where I have to handle the paging/etc manually.  I hope this makes sense...
Gregory
Top achievements
Rank 1
 asked on 07 May 2014
2 answers
287 views
Is it possible to hide grid columns using the css from Bootstrap. I have the following grid control and the data hides as expected but the column names don't.

.Columns(c =>
    {
        c.Bound(col => col.ActiveBool).Width(12).Title("Active").HtmlAttributes(new { @class = "visible-xs visible-lg visible-sm" });
        c.Bound(col => col.District).Width(12).Title("Dist").HtmlAttributes(new { @class = "visible-xs visible-lg visible-sm" });
        c.Bound(col => col.ContractId).ClientTemplate(@Html.ActionLink("#= ContractId #", "ActiveContracts", "ActiveContracts", new { id = "#= ContractId #", @class = "visible-sm visible-lg visible-xs" }, null).ToHtmlString()).Width(16);
        c.Bound(col => col.Status).Width(23).HtmlAttributes(new { @class = "visible-lg" });
        c.Bound(col => col.WorkBeginDate).Width(17).Title("Work Begin").HtmlAttributes(new { @class = "visible-lg" });
        c.Bound(col => col.CurrentAmount).Width(20).HtmlAttributes(new { @class = "visible-lg" });
        c.Bound(col => col.ProjectId).Width(18).HtmlAttributes(new { @class = "visible-lg" });
        c.Bound(col => col.DescriptionTrimmed).Width(33).HtmlAttributes(new { title = "<#=Description#>" }).Title("Description").HtmlAttributes(new { @class = "visible-lg" });
        c.Bound(col => col.County).Width(15).HtmlAttributes(new { @class = "visible-lg" });
        c.Bound(col => col.WorkMixTrimmed).Width(22).HtmlAttributes(new { title = "<#=WorkMix#>" }).Title("Work Mix").HtmlAttributes(new { @class = "visible-lg" });
        c.Bound(col => col.VendorNameTrimmed).Width(22).HtmlAttributes(new { title = "<#=VendorName#>" }).Title("Vendor Name").HtmlAttributes(new { @class = "visible-xs  visible-lg  visible-sm" });
        c.Bound(col => col.ViewMap).Width(15).HtmlAttributes(new { @class = "visible-xs  visible-lg visible-sm" });
    })
Mike
Top achievements
Rank 1
 answered on 07 May 2014
2 answers
390 views
I have code to resize my Tabs to match the browser size.  The problem is when I call this method inside of $(document).ready it does not resize the 1st tab.  The others seem to size just fine.  If I move my call to ResizeTabs outside of $(document).ready then it seems to work fine?  My question is why?

<div>
    @(Html.Kendo().TabStrip()
        .Name("PassportTabStrip")
        .HtmlAttributes(new { style = "height: 100%;" })
        .Items(tabstrip =>
            {
                tabstrip.Add()
                        .Text("Users")
                        .Selected(true)
                        .LoadContentFrom("GetUsers", "Passport");
                tabstrip.Add()
                        .Text("Roles")
                        .LoadContentFrom("GetRoles", "Passport");
                tabstrip.Add()
                        .Text("Functions")
                        .LoadContentFrom("GetFunctions", "Passport");
            })
    )
</div>

$(document).ready(function ()
{
    ResizeTabs();
});

$(window).resize(ResizeTabs);

function ResizeTabs()
{
    var tabstrip = $('#PassportTabStrip');
    var headerHeight = $('header').height();
    var footerHeight = $('footer').height();
    var windowHeight = $(window).height();
    var newHeight = windowHeight - headerHeight - footerHeight - 50;
    tabstrip.css({ height: newHeight + "px" });
    var contentHeight = tabstrip.innerHeight() - tabstrip.children('.k-tabstrip-items').outerHeight() - 16;
    tabstrip.children('.k-content').height(contentHeight);
}
Robert
Top achievements
Rank 1
 answered on 07 May 2014
8 answers
212 views
Hi there,

I have a kendo grid which uses a custom pop up editor which contains an editor control which works fine on desktop devices but on mobile devices the control is not focusable.

I have found that if I run this bit of javascript manually the ability to type appears to work:

$('#ControlName').data("kendoEditor").refresh()

I have done this via Chrome and emulating the ipad environment.

How can I get this control to work in the modal pop up window as my main user base is mobile based and I would prefer to use this control rather than an ugly text area control with no formatting capabilities.


Here is the grid code:

<div id="row8" class="row">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Running log</h4>
</div>
<div class="panel-body">

@(
Html.Kendo().Grid(Model.RunningLogList)
.Name("RunningLogGrid")
.ToolBar(toolbar => toolbar.Create())
.Editable(edit =>
edit.TemplateName("RunningLogEditor").Mode(GridEditMode.PopUp)
.Window(window =>
{
window.HtmlAttributes(new { @class = "kendo-popup-editor" });
})

)
.Columns(
columns =>
{
columns.Bound(c => c.ID).Visible(false);
columns.Bound(c => c.Action);
columns.Bound(c => c.Information);
columns.Bound(c => c.Added);
columns.Bound(c => c.AddedBy);
columns.Command(c => c.Edit());

}
)
.DataSource(ds =>
ds.Ajax()

.Create(create => create.Action("CreateRunningLogEntry", "New", new { area = "CaseStudy", id = Model.ID.ToString() }).Data("sendAntiForgery"))
.Update(update => update.Action("UpdateRunningLogEntry", "New", new { area = "CaseStudy", id = Model.ID.ToString() }).Data("sendAntiForgery"))
.Events(events => events.Error("NewError_Handler"))
.Model(model =>
{
model.Id(m => m.ID);
model.Field(m => m.ID).DefaultValue(Guid.NewGuid());
model.Field(m => m.Added).DefaultValue(DateTime.Now);
model.Field(m => m.AddedBy).DefaultValue(string.Format("{0} {1}",
Common.Library.Claims.ClaimsHelper.ConvertClaim((System.Security.Claims.ClaimsPrincipal)User,System.Security.Claims.ClaimTypes.GivenName ),
Common.Library.Claims.ClaimsHelper.ConvertClaim((System.Security.Claims.ClaimsPrincipal)User,System.Security.Claims.ClaimTypes.Surname )
)
);
model.Field(m => m.StudentID).DefaultValue(Model.ID);
model.Field(m => m.Action);
model.Field(m => m.Information);


})

).Sortable().Pageable().Groupable().Filterable().HtmlAttributes(new { style = "min-height:300px;" }).Scrollable().ColumnMenu()


)


</div>
</div>


<div class="row">
<div class="btn-group pull-left">
<a href="@Url.Action("Index", "Home", new { area="CaseStudy"})" class="btn btn-warning"><span class="glyphicon glyphicon-backward"></span> Back</a>

</div>
<div class="btn-group pull-right">
<button class="btn btn-danger" type="reset"><span class="glyphicon glyphicon-remove"></span> Cancel</button>
<button class="btn btn-primary" type="submit"><span class="glyphicon glyphicon-ok"></span> Save</button>
</div>

</div>
</div>



Here is the editor code:
@model InclusionManagerMVC.Models.StudentRunningLogModels.StudentRunningLogModel


@Html.HiddenFor(m => m.ID)


<div role="form" style="padding:10px;">



<div class="form-group">
@Html.LabelFor(m => m.Action)

@Html.TextBoxFor(m => m.Action, new { @class = "form-control", placeholder = "Enter action" })

</div>

<div class="form-group">
@Html.LabelFor(m => m.Information)

@Html.Kendo().EditorFor(m => m.Information).HtmlAttributes(new { style = "min-width:100%;" }).Deferred(false)

</div>


<div class="form-group">
@Html.LabelFor(m => m.Added)

@Html.Kendo().DateTimePickerFor(m => m.Added).HtmlAttributes(new { style = "min-width:100%;" })

</div>

<div class="form-group">
@Html.LabelFor(m => m.AddedBy)

@Html.TextBoxFor(m => m.AddedBy, new { @class = "form-control", placeholder = "Enter name of person adding..." })

</div>
<div class="help-block">
<p>There will be a section relating to referring the student to panel. Need to decide how this will be activated. </p>
</div>

@Html.Partial("_ErrorPanel")


</div>
Jelly Master
Top achievements
Rank 1
 answered on 07 May 2014
6 answers
651 views
I have a server bound grid that was working fine.  I needed to change it to an ajax bound grid because I needed to add some custom command buttons.  The editor template for the grid contains a dropdownlist which is populated via ViewData in my controller get method.  When I switch the grid to be ajax bound that dropdownlist is throwing an error:

The ViewData item that has the key 'Proposal_Type_ID' is of type 'System.Int32'
but must be of type 'IEnumerable<SelectListItem>'.<BR>

Do I need to change the way the dropdownlist is populated? Or am I doing something else wrong?


Controller:
public ActionResult GetResearchQuestions([DataSourceRequest]DataSourceRequest request)
{
    User user = new User();
    int user_id = user.GetUserIDByBNLAccount(User.Identity.Name);
    string user_facility_id = UserSession.LastViewedUserFacilityID;
 
    if (UserPermissions.VerifyUserFacility(user_id, user_facility_id))
    {
        using (PASSEntities context = new PASSEntities())
        {
            var vm = (from a in context.Proposal_Research_Questions
                      join b in context.Proposal_Types on a.Proposal_Type_ID equals b.ID
                      where b.User_Facility_ID == user_facility_id
                      orderby a.Sort_Order
                      select new ResearchQuestionViewModel()
                      {
                          ID = a.ID,
                          Proposal_Type_ID = a.Proposal_Type_ID,
                          Proposal_Type_Description = b.Description,
                          Question = a.Question,
                          Type = a.Type,
                          Options = a.Options,
                          Required = a.Required,
                          Active = a.Active
                      }).ToList();
 
            var proposalTypes = (from a in context.Proposal_Types
                                 where a.User_Facility_ID == user_facility_id
                                 select a).ToList();
 
            ViewData["ProposalTypes"] = proposalTypes.Select(m => new SelectListItem { Value = m.ID.ToString(), Text = m.Description }).ToList();
 
            DataSourceResult result = vm.ToDataSourceResult(request);
            return Json(result, JsonRequestBehavior.AllowGet);
        }
    }
    else
    {
        return RedirectToAction("Index");
    }
}


View:
@{
    ViewBag.Title = "Research Questions";
}
 
<h2>Proposal Research Questions</h2>
 
@Html.Partial("LastViewedUserFacility")
 
@{ Html.Kendo().Grid<PASSAdmin.ViewModels.UserFacilityAdmin.ResearchQuestionViewModel>()
    .Name("ResearchQuestions")
    .Columns(columns =>
    {
        columns.Command(command => { command.Edit(); }).Width(50);
        columns.Bound(m => m.Question);
        columns.Bound(m => m.Proposal_Type_Description).Title("Proposal Type");
        columns.Bound(m => m.Required).ClientTemplate("#= Required ? '<img src=\\'/Content/images/icons/check.png\\'' : '' #");
        columns.Bound(m => m.Active).ClientTemplate("#= Active ? '<img src=\\'/Content/images/icons/check.png\\'' : '' #");
        columns.Command(command => command.Custom("SortUp").Click("sortUp"));
        columns.Command(command => command.Custom("SortDown").Click("sortDown"));
        columns.Command(command => { command.Destroy(); }).Width(50);
    })
    .ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("UserFacilityAdmin/ResearchQuestion").Window(window => window.Width(500)))
    .Pageable()
    .Sortable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model => model.Id(m => m.ID))
        .Create(create => create.Action("AddResearchQuestion", "UserFacilityAdmin"))
        .Read(read => read.Action("GetResearchQuestions", "UserFacilityAdmin"))
        .Update(update => update.Action("UpdateResearchQuestion", "UserFacilityAdmin"))
        .Destroy(destroy => destroy.Action("DeleteResearchQuestion", "UserFacilityAdmin"))
    )
    .Render();
}
 
<script type="text/javascript">
function sortUp(e) {
    e.preventDefault();
    var id = this.dataItem($(e.currentTarget).closest("tr")).id;
    $.post('/UserFacilityAdmin/UpdateResearchQuestionSortOrder', { id: id, sortChange: -1 }, function (data) {
        $('#ResearchQuestions').data('kendoGrid').dataSource.read();
    });
}
function sortDown(e) {
    e.preventDefault();
    var id = this.dataItem($(e.currentTarget).closest("tr")).id;
    $.post('/UserFacilityAdmin/UpdateResearchQuestionSortOrder', { id: id, sortChange: 1 }, function (data) {
        $('#ResearchQuestions').data('kendoGrid').dataSource.read();
    });
}
</script>



EditorTemplate: (the first field is the one causing the error)
@model PASSAdmin.ViewModels.UserFacilityAdmin.ResearchQuestionViewModel
 
<div class="editor-label">
    @Html.Label("Proposal Type")
</div>
<div class="editor-field">
    @Html.DropDownListFor(model => model.Proposal_Type_ID,  (List<SelectListItem>) ViewData["ProposalTypes"], "(Select One)")
    @Html.ValidationMessageFor(model => model.Proposal_Type_ID)
</div>
 
<div class="editor-label">
    @Html.Label("Question")
</div>
<div class="editor-field">
    @Html.TextAreaFor(model => model.Question, new { style = "width:300px;height:50px;" })
    @Html.ValidationMessageFor(model => model.Question)
</div>
 
<div class="editor-label">
    @Html.Label("Type")
</div>
<div class="editor-field">
    @Html.DropDownListFor(model => model.Type, new SelectList(Model.QuestionTypes, "Value""Text"), "(Select One)")
    @Html.ValidationMessageFor(model => model.Type)
</div>
 
<div class="editor-label">
    @Html.Label("Options")
</div>
<div class="editor-field">
    @Html.TextAreaFor(model => model.Options, new { style = "width:300px;height:50px;" })
    @Html.ValidationMessageFor(model => model.Options)
</div>
 
<div class="editor-label">
    @Html.Label("Required")
</div>
<div class="editor-field">
    @Html.CheckBoxFor(model => model.Required)
    @Html.ValidationMessageFor(model => model.Required)
</div>
 
<div class="editor-label">
    @Html.Label("Active")
</div>
<div class="editor-field">
    @Html.CheckBoxFor(model => model.Active)
    @Html.ValidationMessageFor(model => model.Active)
</div>










Stephen
Top achievements
Rank 1
 answered on 06 May 2014
3 answers
404 views
I have a Kendo().Button on a page that, when clicked, fires a click event to open a Kendo().Window in order to display an alert.  This works fine.  But, if I add a $(document).ready function  to open the window when the document is ready, it does not open the window, and the button does not render properly.

Instead of rendering as a <button> with an <img> property, instead it renders as a plain <button> no image,

Code follows:

​
@{
                            if (@Model.IsClinicalAlert) {
                            @(Html.Kendo().Button()
                                .Name("redalertbutton")
                                .ImageUrl(Url.Content("~/img/patient_alert_red.bmp"))
                                .HtmlAttributes(new { type = "button" })
                                .Events(ev => ev.Click("onAlertClick")))
                            } else {
                                @(Html.Kendo().Button()
                                .Name("greenalertbutton")
                                .ImageUrl(Url.Content("~/img/patient_alert_green.bmp"))
                                .HtmlAttributes(new { type = "button" })
                                .Events(ev => ev.Click("onAlertClick")))
                            }
                            }
 
<script>
    $(document).ready(function () {
        if ($@Model.IsClinicalAlert) {
            alert(@Model.ClinicalAlert);
            var wdw = $("#alertWindow").data("kendoWindow");
            wdw.open();
        }
    });
 
    function onAlertClick(e) {
        var wdw = $("#alertWindow").data("kendoWindow");
        wdw.open();
    }
</script>
@(Html.Kendo().Window()
    .Name("alertWindow")
    .Title("Clinical Alert")
    .Content(@<text><strong>@Model.ClinicalAlert</strong></text>)
    .Draggable()
    .Resizable()
    .Width(400)
    .Modal(true)
    .Visible(false)
    .Position(settings => settings.Top(150).Left(250)))
Dimiter Madjarov
Telerik team
 answered on 06 May 2014
1 answer
112 views
Is there any way to prevent the removal of an item from the select list when a user selects it and maintain the order of the select list?
Alexander Popov
Telerik team
 answered on 06 May 2014
Narrow your results
Selected tags
Tags
Grid
General Discussions
Scheduler
DropDownList
Chart
Editor
TreeView
DatePicker
ComboBox
Upload
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
Accessibility
ListView (Mobile)
Pager
ColorPicker
DateRangePicker
Wizard
Security
Styling
Chat
DateInput
MediaPlayer
TileLayout
Drawer
SplitView
Template
Barcode
ButtonGroup (Mobile)
Drawer (Mobile)
ImageEditor
RadioGroup
Sparkline
Stepper
TabStrip (Mobile)
GridLayout
Badge
LinearGauge
ModalView
ResponsivePanel
TextArea
Breadcrumb
ExpansionPanel
Licensing
Rating
ScrollView
ButtonGroup
CheckBoxGroup
NavBar
ProgressBar
QRCode
RadioButton
Scroller
Timeline
TreeMap
TaskBoard
OrgChart
Captcha
ActionSheet
Signature
DateTimePicker
AppBar
BottomNavigation
Card
FloatingActionButton
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
Bohdan
Top achievements
Rank 3
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Elliot
Top achievements
Rank 1
Iron
Iron
Iron
Sunil
Top achievements
Rank 1
Cynthia
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Bohdan
Top achievements
Rank 3
Iron
Iron
Iron
Rob
Top achievements
Rank 3
Bronze
Bronze
Iron
Elliot
Top achievements
Rank 1
Iron
Iron
Iron
Sunil
Top achievements
Rank 1
Cynthia
Top achievements
Rank 1
Iron
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?