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

[Solved] System.InvalidOperationException: Sequence contains no elements / With MVC3

3 Answers 73 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ntic13
Top achievements
Rank 1
ntic13 asked on 21 Jun 2011, 03:07 PM
Hello,

I'm implementing the treeview of telerik in an MVC3 ASP.NET application.

Im' getting this error :

Exception Details: System.InvalidOperationException: Sequence contains no elements

Source Error:

Line 7:  
Line 8:  @model IEnumerable<MyProject.Models.MyTable>
Line 9: @(Html.Telerik().TreeView()
Line 10: .Name("TreeView") Line 11: .BindTo(Model, mappings =>

the view is there :

@{
    ViewBag.Title = "MyPageTelerik";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
 
<h2>MyPage Telerik</h2>
 
@model IEnumerable<MyProject.Models.MyTable>
@(Html.Telerik().TreeView()
        .Name("TreeView")
        .BindTo(Model, mappings =>
        {
            mappings.For<MyProject.Models.TABLE>(binding => binding
                    .ItemDataBound((item, MyTable) =>
                    {
                        item.Text = MyTable.Parent;
                    })
                    .Children(MyTable=> MyTable.Alias_Child));
             
            mappings.For<MyProject.Models.MyTable>(binding => binding
                    .ItemDataBound((item, child) =>
                    {
                        item.Text = child.Alias_Child;
                    }));
        })
)


the action in the controller is there :

public ActionResult MyActionTelerik()
{
    return View(MyTable.GetParents());
}

and the model is there :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Oracle.DataAccess.Client;
using System.Collections;
using System.Data.Linq;
 
namespace MyProject.Models
{
    public class MyTABLE
    {
        private string CHILD_ID;
        private string PARENT;
        private string ALIAS_CHILD;
 
 
 
        public FIC_AXE_MOT(string child_id, string parent, string alias_child)
        {
            this.Child_Id = Child_id;
            this.Parent = parent;
            this.Alias_Child = alias_Child;
        }
 
        public virtual string Child_Id
        {
            get { return CHILD_ID; }
            set { CHILD_ID = value; }
        }
 
        public virtual string Parent
        {
            get { return PARENT; }
            set { PARENT = value; }
        }
 
        public virtual string Alias_Child
        {
            get { return ALIAS_Child; }
            set { ALIAS_CHILD = value; }
        }
 
 
        public static IEnumerable<MyTABLE> GetParents()
        {
            IEnumerable<FIC_AXE_MOT> monIEnumerable = null;
            ArrayList monArray = new ArrayList();
            string _CHILD_ID;
            string _PARENT;
            string _ALIAS_CHILD;
 
 
 
            string connString = "Data Source = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = muhost.fr)(PORT = 1531)))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = MySERV))); User Id=admin;Password=admin;";
 
            OracleConnection connOracle = new OracleConnection(connString);
            connOracle.Open();
            OracleCommand cmdObj = connOracle.CreateCommand();
            cmdObj.CommandText = "SELECT * FROM MyTable";
            OracleDataReader rdrObj = cmdObj.ExecuteReader();
 
            if (rdrObj.HasRows)
            {
                while (rdrObj.Read())
                {
                    _CHILD_ID = rdrObj.GetString(rdrObj.GetOrdinal("CHILD"));
                    _PARENT = rdrObj.GetString(rdrObj.GetOrdinal("PARENT"));
                    _ALIAS_CHILD = rdrObj.GetString(rdrObj.GetOrdinal("ALIAS_CHILD"));
                                   
                                         
                    MyTable objMyTable = new MyTable(_CHILD_ID,_PARENT,_ALIAS_CHILD);
 
                    monArray.Add(objMyTable );                   
 
                };
            };
 
            monIEnumerable= monArray.Cast<MyTable>();
 
             
            return monIEnumerable;
        }
 
 
 
    }
}


thank you for help.

3 Answers, 1 is accepted

Sort by
0
A
Top achievements
Rank 1
answered on 23 Aug 2011, 10:40 PM
Hey, did you find an answer? I also have this problem...
0
ntic13
Top achievements
Rank 1
answered on 24 Aug 2011, 08:55 AM
No didn't find a solution, a abandon the use of Telerik in my MVC, Telerik doesnt work with MVC
0
Atanas Korchev
Telerik team
answered on 24 Aug 2011, 09:04 AM
Hi all,

Is there a chance to provide the full stacktrace? I am asking you for more details because there are quite many reasons for this exception to occur.

I am not sure what to respond to the comment that Telerik does not work with MVC. This is obviously not true.

Regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
TreeView
Asked by
ntic13
Top achievements
Rank 1
Answers by
A
Top achievements
Rank 1
ntic13
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or