|
-
May 20th, 2011, 10:54 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Decrement displaying of data
I want to make a "announcements" page and what I want to happen is that when a user posts a news, the post will be saved into the database and is defined by a unique ID (using autonumber). So data is arranged by that.
When a user loads the page, announcements will be displayed from lastest to oldest.
So what I'm trying to ask here is how can I list data from latest to oldest.
The container of the announcements is below
Code:
<table >
<tr>
<th>
Date Posted
</th>
<th>
Author
</th>
<th>
Title
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.NewsDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Author)
</td>
<td>
@Html.DisplayFor(modelItem => item.NewsTitle)
</td>
<td>
@Html.ActionLink("Read", "Details", new { id=item.ID })
</td>
</tr>
}
Edit: Is there a way that " @Html.DisplayFor(modelItem => item.NewsTitle)" will funtion as a link similar to @Html.ActionLink("Read", "Details", new { id=item.ID })?
Last edited by azsx123; May 20th, 2011 at 12:19 PM.
-
May 21st, 2011, 09:00 AM
#2
Re: Decrement displaying of data
Hello,
Looks to me like you are doing ASP.Net MVC, so I am going to more this question over to the ASP.Net MVC forum.
Gary
-
May 21st, 2011, 11:22 AM
#3
Hyperactive Member
Re: Decrement displaying of data
Order the data when you retrieve it from your repository. (How depends how you query the data. LINQ in most my work. orderby dateValue descending)
As for the 2nd question
@Html.ActionLink(item.NewsTitle, "Read", "Details", new { id=item.ID })
(think the parameters is displaytext, action, controller, attributes)
-
May 21st, 2011, 11:34 AM
#4
Thread Starter
Addicted Member
Re: Decrement displaying of data
 Originally Posted by Krokonoster
Order the data when you retrieve it from your repository. (How depends how you query the data. LINQ in most my work. orderby dateValue descending)
I'm using Sql server ce.
 Originally Posted by Krokonoster
As for the 2nd question
@Html.ActionLink(item.NewsTitle, "Read", "Details", new { id=item.ID })
(think the parameters is displaytext, action, controller, attributes)
I see. Thanks!
-
May 21st, 2011, 12:03 PM
#5
Hyperactive Member
Re: Decrement displaying of data
Do you have a domain model hooked up to your database (the latter not being important here)?
How you query the domain model then? LINQ?
Or do you directly query the database in your controller (hope not).
Either case you can use orderby.
-
May 21st, 2011, 12:30 PM
#6
Thread Starter
Addicted Member
Re: Decrement displaying of data
I don't use queries. None as of I know of. I i'm using the login function that came with the MVC 3 layout
-
May 21st, 2011, 12:32 PM
#7
Hyperactive Member
Re: Decrement displaying of data
Then where does that code you posted come from? That ain't part of the default template.
-
May 21st, 2011, 12:35 PM
#8
Thread Starter
Addicted Member
Re: Decrement displaying of data
Are you pertaining to the controller?
Code:
// GET: /News/
public ViewResult Index()
{
return View(db.BatchNews.ToList());
}
I've been looking for the quries myself but am unable to do so.
-
May 21st, 2011, 12:42 PM
#9
Hyperactive Member
Re: Decrement displaying of data
Pseudo code, trust you can figure it out:
Code:
IList<NewsItem> items = (from item in db.BatchNews
orderby item.NewsDate
select item).ToList();
return View(items);
-
May 21st, 2011, 12:43 PM
#10
Thread Starter
Addicted Member
Re: Decrement displaying of data
I do. Thanks so much! =)
Edit: Its not working.
Code:
public ViewResult Index()
{
IList<NewsModel> items = (from item in db.BatchNews
orderby item.ID descending
select item).ToList();
return View(db.BatchNews.ToList());
}
Last edited by azsx123; May 21st, 2011 at 01:01 PM.
-
May 24th, 2011, 01:02 AM
#11
Re: [RESOLVED] Decrement displaying of data
Hello,
When you say something is not working, can you please provide some more information?
i.e. what exactly isn't working, and what steps have you taken to test it.
Was there an exception? If so, what was it? Did it not compile? If not, what was the error?
In order to best help you out, you need to help us out by providing as much information as possible.
Gary
-
May 24th, 2011, 02:48 AM
#12
Hyperactive Member
Re: Decrement displaying of data
 Originally Posted by azsx123
I do. Thanks so much! =)
Code:
public ViewResult Index()
{
IList<NewsModel> items = (from item in db.BatchNews
orderby item.ID descending
select item).ToList();
return View(db.BatchNews.ToList());
}
return View(items);
Second on what Gary said. Think carefully what information others will need to help you and include that. (That does not mean posting 100's lines of irrelevant code).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|