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

Passing the two models to a view in ASP.NET

6 Answers 170 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 12 Aug 2014, 08:41 AM
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

6 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 14 Aug 2014, 09:05 AM
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.

 
0
Richard
Top achievements
Rank 1
answered on 14 Aug 2014, 10:46 AM
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?!

0
Alex Gyoshev
Telerik team
answered on 14 Aug 2014, 03:06 PM
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.

 
0
Richard
Top achievements
Rank 1
answered on 15 Aug 2014, 08:34 AM
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
0
Jon
Top achievements
Rank 1
answered on 02 Dec 2015, 03:22 PM

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

0
Alex Gyoshev
Telerik team
answered on 04 Dec 2015, 07:45 AM

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
Tags
Gantt
Asked by
Richard
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Richard
Top achievements
Rank 1
Jon
Top achievements
Rank 1
Share this question
or