PetaPoco, MvcContrib Grid and Pagination

I’m using PetaPoco and MvcContrib in my current project.

I had a devil of a time finding a decent example of paging a grid in an efficient manner.

Here’s what I’ve got so far.

The Action should look like this:

——————— public ActionResult Index(int? page) { //Normally, with a big ORM, using AsPagination to lazy Paginate would work fine. //but it’s in-efficient to do this using PetaPoco //var  dbPage = Db.Query<SomeModel>(”") //    .AsPagination(page ?? 1, 10); //…so we’ll do it the PetaPoco way for efficient results var dbPage = Db.Page<SomeModel>(page ?? 1, 10, “”); //see if the Db really ran efficient sql Trace.Write(Db.LastCommand, “SQL to get resulsts”); //instead of AsPagination use CustomPagination which provides a “TotalItems” param var viewModel = new CustomPagination<SomeModel>( dbPage.Items, (int)dbPage.CurrentPage, (int)dbPage.ItemsPerPage, (int)dbPage.TotalItems); return View(viewModel); } —————————-
————–

@using MvcContrib.UI.Grid;

@using MvcContrib.UI.Pager;

@using MvcContrib.Pagination;

@model IPagination<SomeModel>

@{

ViewBag.Title = “Some Stuff”;

}

<h2>

Some Stuff to Page in a Grid</h2>

<div id=”grid”>

@Html.Grid(Model).AutoGenerateColumns()

</div>

<div id=”pager”>

@Html.Pager(Model).First(”First”).Next(”Next”).Previous(”Prev”).Last(”Last”).Format(”{0}-{1} of {2}&nbsp;&nbsp;&nbsp;&nbsp;”)

</div>

</div>

————————-

Here is an extension method to wrap up the CustomPagination.

So now the action method can be a bit tighter

And the View needs to look a little something like this:

Hope that helps
-Denis

Weird.

For a while there all my requests to google were going to various pages at microsoft. Yipes. Smelled like a nasty virus. Didn’t expect to see anything like that on my MAC! All browsers behaved the same. I opened my hosts file. Nothing odd there. After reading the hosts file it stopped doing it.

Very strange.

Button type=’button’

Do yourself a big favor… and by ‘yourself’ I mean ‘myself’, and by favor I mean…

When you put a<button> tag on an html document. ALWAYS set the type attribute to ‘button’.

<button type=”button”>Click Me!</button>

Seems redundant, but several browsers are known to treat ALL buttons as type=’submit’. Which can be frustrating when you’ve gone to the trouble of putting a bunch of javascript in to prevent the post back if validation fails.

So basic, yet it still bites me, even after all these years.

Ref:
http://www.w3schools.com/tags/tag_button.asp

Snipplr and Snipt

I ran across a couple interesting sites that host code snippets.

Here are some code samples:

First, Snipplr:

And here is Snipt:

Wow, they both do a nice job and it’s stupid-easy to paste their ‘embed’ scripts into the page. I’m leaning towards Snipt. Looks nice and the branding is less conspicuous.

Both of these services have WordPress plugins. But not having to mess with all that is sort of the whole point for me, so I’m not going to bother testing those out at the moment.

Features aside, I’d like to pick the one that has the strongest community. Snipplr seems to have vastly more code snippets, especially for c# and other MS technologies. The searching and tagging seems to work much better on Snipplr, too.

But I have to admit that Snipt has all but seduced me with their tasty style.

It just occurred to me that there may be a major drawback to keeping code on a separate site. Search. Hmmmmmmm. What to do.

When will Microsoft provide the next WSS Developer VPC Image?

I’ve been worrying about when and if Microsoft is going to update their WSS Developer VPC image. The one they published last year is still available here:

http://www.microsoft.com/downloads/details.aspx?FamilyID=1beeac6f-2ea1-4769-9948-74a74bd604fa&displaylang=en

…and yet it just expired.

Unfortunately I recommended to a lot of folks (at a dnug presentation, and here: http://dkitchen.net/blog/?p=166) that they would do well to develop on this image. I recalled proudly that last year, Microsoft freshened the VPC image from the previous year, so “certainly they can be counted on to do the same this year.”

Oops.

My apologies to any trusting friends and colleagues. I’m just another sorry, trusting soul out there along with the rest of you.