logo

New Response

« Return to the blog entry

You are replying to:

    • avatar
    • S.
    • Posted on Fri 4 Feb 2011 09:31 AM

    It's nice knowing you have liked it ^^

    After following your blog for many years (and learning a lot about Lotus thanks to it). I hoped you'll also follow the way of the MVC. Not just because I would have an extra excuse to keep following your blog, but because you always looked as a great web programmer, and hopefully with MVC you will be able to make much more interesting things.

    As I've been following your blog for so long, I would bet at sometime you'll want to use Ext/Sencha or jQuery, or JSON with any other JS library. This little code might not look like much, but it made me incredibly happy when I discovered C# anonymous classes (sorry for the formatting):

    public ActionResult animals() {

    try {

    var animals = ctx.Animals.Select(an=> new { name = an.Description; type = an.Family.Description }).ToList();

    return Json( new { success = true; data = animals } );

    catch(Exception ex) {

    return Json( new { success = false; errorMsg = ex.Message });

    }

    }

    I've written it just like that, so there might be errors (ctx should be the datacontext). You will be able to call the action and get json object in the browser that contains an array (called data) with the names and families of each animal. Creating an anonymous object also allows us to return wether there have been any errors, and if there was, the error message.

    Did I say I love MVC + Linq? :)

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment: