ASP.NET MVC & jQuery development

April Fresno-area .NET user group wrap up

I haven’t been able to make it out to the Fresno-area .NET user group in a while, but I’m glad I did for the one this last Wednesday (held at Fresno State).

The topic of the night was NHibernate (and several related technologies) given by Jeff Doolittle. Jeff’s the CTO of Lotpath (built on ASP.NET MVC), so he and his company are definitely eating their own dogfood with what he presented. The slides and code are available which will be great for review for anyone diving into it.

After the presentation and questions, quite a bit of networking went on. I talked to several developers I hadn’t before, including a recent FSU grad who’s been developing iPhone and Android apps for Watch Do It. Swag, books and full-on software licenses were raffled out at the end as well (I won a copy of ReSharper!). Even after we were kicked out, several of us hit Doghouse Grill for another hour or so.

Needless to say, if you’re a developer in Fresno, this is definitely a good group to attend and meet other local geeks at. The subject matter spans quite a bit, half the time not even .NET specific. Thanks to Gustavo Cavalcanti, who’s been organizing this user group for some time now. Send him an email if you want to get on the list. The next one is on May 13.

That being said, there’s also groups for Drupal, designers, and social media. I’m sure there’s more, so let us know.

In addition, check out the Fresno-area techies wiki. Request access, add yourself to the directory, and post any local events such as this one.

Next up: the 59 Days of Code kicks off on Friday, April 23 at 10pm. Hope to see some of you there!

Zen, a web app built with ASP.NET MVC 2 and jQuery

I was fortunate enough to attend Microsoft’s MIX conference for the first time this year. I learned a ton, jotted down hundreds of ideas for my projects, and had some valuable discussions with a lot of smart people.

Obviously you have to attend in person to network, but fortunately all the videos and slides are being made available online. Even for attendees this is great for review, but also because you inevitably miss a ton of sessions because of the schedule.

At the very end, I attended a great session by the co-founder and developer of Zen, Nate Kohari. It’s a unique project management web app written in ASP.NET MVC 2 and jQuery. Nate’s the sole developer and this is his major product. It’s a business that charges for certain levels of usage, not a free-to-use or open source app created for fun. It was refreshing to go through something more in line with my own goals. See the video and slides for yourself.

Some of the technology Zen is using:

My plan is to convert Out of Eggs to ASP.NET MVC 2, then explore some of these other technologies for use within it and other projects I’m currently working on.

Announcing 59 Days of Code (a Fresno-area web & mobile app competition)

I’m excited to announce the CVBI is officially kicking off a web & mobile app showcase/competition for the Fresno area.

59daysofcode.com

Fresnans know all too well that we’re not commonly referred to as a hub for tech startups and talent, so this is definitely a boon for the local community. Sure, I’m stoked to enter Out of Eggs into the “In Progress” category of the contest. And it would definitely be nice to win a prize. But more importantly, I’m eager to see all the other apps that join in along with their enthusiasm and creativity. And will this competition significantly boost recognition of local talent by the community and investors? I sure hope so.

Also see:

http://twitter.com/59daysOfCode
http://blog.irmsgeekwork.com/2010/the-59daysofcode-web-mobile-apps-competition

Out of Eggs, a web app built in ASP.NET MVC, jQuery & jQuery UI

I’m excited to announce outofeggs.com, a web app I’ve been working on for a while. It’s built on the techniques I’ve gone through in my Categorized Item List series (using ASP.NET MVC, jQuery & jQuery UI). Just create a list and see for yourself. The back end is SQL Server 2008.

It probably goes without saying that I could use any and all feedback: bugs that pop up, features you’d like to see, usability issues, etc. Also let me know if there’s any development-related aspects of the app you’d like me to share in a post that I haven’t covered yet.

Drag and Drop Categorized Item List with jQuery and ASP.NET MVC – Part 4

Controllers and AJAX

This is part 4 of a series. In this post I’ll go through the controller classes and how to use jQuery and AJAX to update the database with the position (or state) of where each section and item is moved to.

Every section can be dragged and dropped into any of the 4 columns and in any position within that column. This is the reason for both the ColumnNum and SortOrder fields of the Sections table described in part 2.

First we’ll dive into jQuery. Going back to our sortable() call for the sections, we need to add code that fires after an update event. The important thing to note here is that the update event will fire for both the column moving from and to. If moving within the same column, it’ll fire only once.

As set up in part 3, the column num is stored in the id attribute of the “listColumn” div, so with a little parsing we can retrieve the column who’s state just changed.

Next we’ll need the new order of the sections within each changed column. The sortable(“serialize”) call forms the section IDs into a “form/ajax submittable string” like this:

section[]=3&section[]=1&section[]=4

For more detail see the jQuery UI sortable page. Look under Methods > serialize.

Now we’ll do an AJAX post to a method within the section controller we’ll create below. Here’s the resulting jQuery:

function InitSectionSorting()
{
    $(".listColumn").sortable(
    {
        …,
        //update event fires both for column leaving and receiving
        update: function(event, ui)
        {
            //Extract column num from current div id
            var colNum = $(this).attr("id").replace(/col_/, "");

            $.post("/Section/UpdateSortOrder",
            { columnNum: colNum, sectionIdQueryString: $(this).sortable("serialize") });
        }
    });
}

In SectionController.cs, we’ll now code the UpdateSortOrder method to receive the serialized string from jQuery and pass it as a string array to it’s model class.

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateSortOrder(int columnNum, string sectionIdQueryString)
{
    string[] separator = new string[2] { "section[]=", "&" };
    string[] sectionIdArray = sectionIdQueryString.Split(separator, StringSplitOptions.RemoveEmptyEntries);

    secRepo.UpdateSortOrder(columnNum, sectionIdArray);
    secRepo.Save();

    return Content("Success");
}

The return Content(“Success”) is simply to see that the update was successful using Firebug. You should see the text “Success” within Firebug’s Console tab after you drag and drop a section. It’s optional so you can remove it.

Now on to Items. They can be moved to any section and in any position, so the jQuery and controller code is almost the same Sections.

jQuery:

function InitItemSorting()
{
    $(".itemList").sortable(
    {
        ...,
        //update event fires both for item list leaving and receiving
        update: function(event, ui)
        {
            //Extract section id from parent section box
            var sectionId = $(this).closest(".secBox").attr("id").replace(/section_/, "");

            $.post("/Item/UpdateSortOrder",
                { sectionId: sectionId, itemIdQueryString: $(this).sortable("serialize") });
        }
    });
}

ItemController.cs:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateSortOrder(long sectionId, string itemIdQueryString)
{
    string[] separator = new string[2] { "item[]=", "&" };
    string[] itemIdArray = itemIdQueryString.Split(separator, StringSplitOptions.RemoveEmptyEntries);

    itemRepo.UpdateSortOrder(sectionId, itemIdArray);
    itemRepo.Save();

    return Content("Success");
}

In a later series we’ll cover editing the text of (and deleting) sections and items.

Download the source code (requires Visual Studio 2008 and ASP.NET MVC 1.0)



I'm an ASP.NET MVC & jQuery developer, creator of outofeggs.com, and a proponent of tech in the central valley. Contact me on Twitter or email.

Projects

Subscribe by Email

Enter your email address: