Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

Posts Tagged ‘JSGenerator

MR, Ajax & JSGenerator

with one comment

A friend stabbed and asked me

How do I control ajax delete scenario where I want to remove table row if deleted is successful otherwise I will alert user that they can’t delete this particular record?

Sound very familiar right? The beauty of MR is it leverage your existing web development skills, and just believe me when I tell you so.

Now let take a look at how MR JSGenerator would solve the problem described above, let see our action code:

public void AjaxTest(int id){
if (id < 0) { PropertyBag["err"] = "Woop! what are you talking about?"; } // for some reason I had to flow the code down PropertyBag["id"] = id; } ... [/sourcecode] Now the view part (*.brailjs) [sourcecode language='javascript'] if IsDefined("err"): page.Alert(err) else: page.Alert("Id = " + id) end [/sourcecode] No hack no tweak but what about the result? well it safe to try that yourself at home. Is there any JSGenerator in ASP.NET MVC? I doubt that. Edit: I suppose to be able to do cooler code, but this bug prevented me

Written by Chorn Sokun

November 7, 2008 at 11:15 am

Posted in MonoRail, Tips & Tricks

Tagged with ,