Passing the two models to a view in ASP.NET

7 posts, 0 answers
  1. Richard
    Richard avatar
    18 posts
    Member since:
    Jun 2014

    Posted 12 Aug 2014 Link to this post

    I'm grappling with how to pass two views to the Gantt chart properly.  I notice from the examples that Telerik are using Services to provide the datasources but I really wanted to Strongly Type my (partial) view and maintain the MV(VM)C convention.

    So I have:

    Viewmodel:
    Namespace Models
     
        Public Class Tasks
            <Key> <Display(Name:="Job")> Public Property TaskID As Integer
            <Display(Name:="Project Name")> Public Property Title As String
            <Display(Name:="Start")> Public Property StartDate As Date
            <Display(Name:="End")> Public Property EndDate As Date
        End Class
     
        Public Class Dependencies
            <Key> <Display(Name:="Dependency Id")> Public Property DependencyID As Integer
            <Display(Name:="Predecessor Id")> Public Property PredecessorId As Integer
            <Display(Name:="Successor Id")> Public Property SuccessorId As Integer
            <Display(Name:="Type")> Public Property Type As Integer
        End Class
     
        Public Class TypeDep
            Public Task As IEnumerable(Of Tasks)
            Public Dep As IEnumerable(Of Dependencies)
        End Class
    End Namespace


    Controller:
    Dim iTasks As IEnumerable(Of Models.Tasks)
    Dim iDeps As IEnumerable(Of Models.Dependencies)
    Dim TD As New Models.TypeDep
    TD.Task = iTasks
    TD.Dep = ideps   
    Return PartialView("Gantt", TD)


    View:
    @ModelType ienumerable(Of IMS_2.Models.Typedep)
     
    @(Html.Kendo().Gantt(Model).Name("chart").Title("Example Column Chart"))

    I'm getting a syntactical error in the view in respect of TTaskModel not being able to be inferred.  I can't find any examples of this approach - could anyone give me guidance?

    Many thanks

  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 14 Aug 2014 Link to this post

    Hello Richard,

    The Task and Dependency classes need to inherit the IGanttTask and IGanttDependency interfaces, and the Gantt is bound to both collections.

    Html.Kendo().Gantt(Of Models.Tasks,Models.Dependencies)(Model.Task, Model.Dep)

    Regards,
    Alex Gyoshev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Richard
    Richard avatar
    18 posts
    Member since:
    Jun 2014

    Posted 14 Aug 2014 in reply to Alex Gyoshev Link to this post

    That's great - thanks Alex - I have made considerable progress.  And am now getting a different error!

    Viewmodel:
    Public Class Task
        Implements IGanttTask
        <Key> <Display(Name:="Job")> Public Property ID As Integer
        <Display(Name:="Project Name")> Public Property Title As String Implements IGanttTask.Title
        <Display(Name:="Start")> Public Property Start As Date Implements IGanttTask.Start
        <Display(Name:="End")> Public Property [End] As Date Implements IGanttTask.End
        Public Property ParentID As Integer
        Public Property OrderID As Integer Implements IGanttTask.OrderId
        Public Property PercentComplete As Decimal Implements IGanttTask.PercentComplete
        Public Property Expanded As Boolean Implements IGanttTask.Expanded
        Public Property Summary As Boolean Implements IGanttTask.Summary
    End Class
     
    Public Class Dependency
        Implements IGanttDependency
        <Key> <Display(Name:="Dependency Id")> Public Property DependencyID As Integer
        <Display(Name:="Predecessor Id")> Public Property PredecessorId As Integer
        <Display(Name:="Successor Id")> Public Property SuccessorId As Integer
        <Display(Name:="Type")> Public Property Type As Integer
    End Class
     
    Public Class TypeDepVM
        Public Property Tasks As IEnumerable(Of Task)
        Public Property Dependencies As IEnumerable(Of Dependency)
    End Class

    View:
    @ModelType IMS_2.Models.TypedepVM
     
    <div class="gantt-wrapper">
        @(Html.Kendo().Gantt(Of IMS_2.Models.Task, IMS_2.Models.Dependency)(Model.Tasks, Model.Dependencies).Name("gantt"))
    </div>

    In VS2013 the 'Html.Kendo().Gantt(Of IMS_2.Models.Task, IMS_2.Models.Dependency)' is flagged as having the following error:

    Error 2 Class 'Kendo.Mvc.UI.Fluent.GanttBuilder(Of IMS_2.Models.Task, IMS_2.Models.Dependency)' cannot be indexed because it has no default property.

    Anyone any idea?!

  5. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 14 Aug 2014 Link to this post

    Hello Richard,

    It seems that I have misguided you a bit in my previous post -- you need to declare the Gantt DataSource and DependenciesDataSource instead of passing the data to the Gantt() method. Right now, passing the Model directly is not supported by the server-side wrappers, but I have logged this for consideration.

    Regards,
    Alex Gyoshev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Richard
    Richard avatar
    18 posts
    Member since:
    Jun 2014

    Posted 15 Aug 2014 in reply to Alex Gyoshev Link to this post

    Ok Thanks Alex.

    Ideally I'd like to use the Strongly Typed View approach throughout the project (the Grid method accepts it just fine), but  I can learn how to build the datasource methods.  It would be great if ultimately all of the Kendo MVC helpers could be bound in the same way :-)

    Regards
  7. Jon
    Jon avatar
    53 posts
    Member since:
    Oct 2013

    Posted 02 Dec 2015 in reply to Alex Gyoshev Link to this post

    This post is over 18 months old but I am wondering if Kendo Grids can now be bound to models? I was trying to do this and got the same error message about not being able to index and there is no default property.

    Thanks

  8. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 04 Dec 2015 Link to this post

    Hello Jon,

    Yes, the Gantt can be bound to model via the server-side wrappers:

       <%= Html.Kendo().Gantt(ViewBag.Tasks).Name("Gantt") %>

     

    Regards,
    Alex Gyoshev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready