can you check the data from controller weather its cotnains it has id or not
var model=data.Events.Select(i =>
new
{ end_date=i.end_date, room_id = i.room_id, start_date = i.start_date, text = i.text, id = i.EntryID }).Distinct();
MyEventsDataContext data = new MyEventsDataContext();
var array = (
from e in data.Events.ToList()
where (e.EntryID != null)
group e by new { e.EntryID, e.text, e.start_date, e.end_date }
into g
select new { user_id = g.Max(j => j.User.UserId), color = g.Max(j => j.User.color), text = g.Key.text, start_date = g.Key.start_date, end_date = g.Key.end_date, id = g.Max(j => j.id) }
).AsQueryable();
return View(array);
}
How can i call from .aspx pages. I did aspx page, but i guest something wrong at there. Here what i have done:-
public ActionResult Data() {
MyEventsDataContext data = new MyEventsDataContext();
Event events = new Event();
List<Event> array = (
from e in data.Events.ToList()
where (e.EntryID != null)
group e by new { e.EntryID, e.text, e.start_date, e.end_date }
into g
select new Event { user_id = g.Max(j => j.User.UserId), text = g.Key.text, start_date = g.Key.start_date, end_date = g.Key.end_date, id = g.Max(j => j.id) }
).ToList<Event>();
return View(array);
}
But still not working. Can you let me know what wrong with it?
micnie2020
Member
306 Points
524 Posts
'object' does not contain a definition for 'id'
Apr 10, 2012 05:46 AM|LINK
I trying to call data from controller through .aspx page, unfortunately i got error:-
"'object' does not contain a definition for 'id'"
Please advise.
Thank you.
Controller
public ActionResult Data()
{
MyEventsDataContext data = new MyEventsDataContext();
return View(data.Events.Select(i => new { end_date=i.end_date, room_id = i.room_id, start_date = i.start_date, text = i.text, id = i.EntryID }).Distinct());
}
aspx
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" ContentType="text/xml" %>
<data>
<%foreach (var myevent in Model) { %>
<event id="<%=myevent.id%>" textColor="<%= (myevent.start_date < DateTime.Now ? "gray" : myevent.User.color) %>">
<start_date><![CDATA[<%= String.Format("{0:dd/MM/yyyy HH:mm}",myevent.start_date) %>]]></start_date>
<end_date><![CDATA[<%= String.Format("{0:dd/MM/yyyy HH:mm}",myevent.end_date) %>]]></end_date>
<text><![CDATA[<%= Html.Encode(myevent.text)%>]]></text>
<room_id><![CDATA[<%= myevent.room_id %>]]></room_id>
<user_id><![CDATA[<%= myevent.user_id.ToString() %>]]></user_id>
</event>
<% } %>
</data>
Jack Hunt
Participant
1270 Points
713 Posts
Re: 'object' does not contain a definition for 'id'
Apr 10, 2012 05:56 AM|LINK
you have not declare id when you get data in query,,you have to get id in your query and column name should be 'id'
mit's Website
Mitesh N Vaishnav
micnie2020
Member
306 Points
524 Posts
Re: 'object' does not contain a definition for 'id'
Apr 10, 2012 06:00 AM|LINK
Hi,
I did that in controller, i have bold the section as below. Please advise what is wrong.
Thank you.
Controller
public ActionResult Data()
{
MyEventsDataContext data = newMyEventsDataContext();
return View(data.Events.Select(i => new { end_date=i.end_date, room_id = i.room_id, start_date = i.start_date, text = i.text, id = i.EntryID }).Distinct());
}
dharnendra
Contributor
2955 Points
551 Posts
Re: 'object' does not contain a definition for 'id'
Apr 10, 2012 06:04 AM|LINK
can you check the data from controller weather its cotnains it has id or not
var model=data.Events.Select(i => new { end_date=i.end_date, room_id = i.room_id, start_date = i.start_date, text = i.text, id = i.EntryID }).Distinct();
return View(model);
Check the model data for id field.
Technical Leader
GTL-Ahmedabad
micnie2020
Member
306 Points
524 Posts
Re: 'object' does not contain a definition for 'id'
Apr 10, 2012 06:27 AM|LINK
Still same error raised.
Thank you.
Please advise.
dharnendra
Contributor
2955 Points
551 Posts
Re: 'object' does not contain a definition for 'id'
Apr 10, 2012 06:42 AM|LINK
debug and check the model (var model) in controller for "id" parameter. That will provide you the hint of the issue.
Technical Leader
GTL-Ahmedabad
micnie2020
Member
306 Points
524 Posts
Re: 'object' does not contain a definition for 'id'
Apr 10, 2012 08:44 AM|LINK
Hi All,
I have controller:
public ActionResult Data() {
MyEventsDataContext data = new MyEventsDataContext();
var array = (
from e in data.Events.ToList()
where (e.EntryID != null)
group e by new { e.EntryID, e.text, e.start_date, e.end_date }
into g
select new { user_id = g.Max(j => j.User.UserId), color = g.Max(j => j.User.color), text = g.Key.text, start_date = g.Key.start_date, end_date = g.Key.end_date, id = g.Max(j => j.id) }
).AsQueryable();
return View(array);
}
How can i call from .aspx pages. I did aspx page, but i guest something wrong at there. Here what i have done:-
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" ContentType="text/xml" %>
<data>
<% foreach (var myevent in Model) { %>
<event id="<%=myevent.id%>" textColor="<%= (myevent.start_date < DateTime.Now ? "gray" : myevent.color) %>">
<start_date><![CDATA[<%= String.Format("{0:dd/MM/yyyy HH:mm}",myevent.start_date) %>]]></start_date>
<end_date><![CDATA[<%= String.Format("{0:dd/MM/yyyy HH:mm}",myevent.end_date) %>]]></end_date>
<text><![CDATA[<%= Html.Encode(myevent.text)%>]]></text>
<room_id><![CDATA[<%= myevent.room_id %>]]></room_id>
<user_id><![CDATA[<%= myevent.user_id.ToString() %>]]></user_id>
</event>
<% } %>
</data>
Now i get error on .aspx pages:-
'object' does not contain a definition for 'id'
ignatandrei
All-Star
135037 Points
21649 Posts
Moderator
MVP
Re: 'object' does not contain a definition for 'id'
Apr 10, 2012 08:49 AM|LINK
1.
Do you need to use dynamic? Please use the type
2.
instead of var, put the type of the myevent .
micnie2020
Member
306 Points
524 Posts
Re: 'object' does not contain a definition for 'id'
Apr 10, 2012 09:15 AM|LINK
Hi Ignatandrei,
I have changed the aspx to be:-
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<List<Event>>" ContentType="text/xml" %>
<data>
<% foreach (var events in Model) { %>
<event id="<%=events.id%>" textColor="<%=(events.start_date < DateTime.Now ? "gray" : events.User.color)%>">
<start_date><![CDATA[<%=String.Format("{0:dd/MM/yyyy HH:mm}",events.start_date)%>]]></start_date>
<end_date><![CDATA[<%=String.Format("{0:dd/MM/yyyy HH:mm}",events.end_date)%>]]></end_date>
<text><![CDATA[<%=Html.Encode(events.text)%>]]></text>
<room_id><![CDATA[<%=events.room_id%>]]></room_id>
<user_id><![CDATA[<%=events.user_id.ToString()%>]]></user_id>
</event> <% } %>
</data>
My controller had been modify to be:-
public ActionResult Data() {
MyEventsDataContext data = new MyEventsDataContext();
Event events = new Event();
List<Event> array = (
from e in data.Events.ToList()
where (e.EntryID != null)
group e by new { e.EntryID, e.text, e.start_date, e.end_date }
into g
select new Event { user_id = g.Max(j => j.User.UserId), text = g.Key.text, start_date = g.Key.start_date, end_date = g.Key.end_date, id = g.Max(j => j.id) }
).ToList<Event>();
return View(array);
}
But still not working. Can you let me know what wrong with it?
Please advise.
Thank you.
ignatandrei
All-Star
135037 Points
21649 Posts
Moderator
MVP
Re: 'object' does not contain a definition for 'id'
Apr 10, 2012 10:05 AM|LINK
Could you please tell what you mean by
?And see ( wild guess) http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx