Getting typed JSon in TypeScript using Weld

1. June 2013 20:32 by admin in .net, DRY, jQuery, MVC, typescript, Weld
Imagine you have a MVC controller exposing a Person as following: 

public JsonResult GetPerson(int id)
return Json(new Person
First = "Barack",
Last = "Obama"
Now I want to use this client side. I want to update my "first" span with the First property of the person I get back from the server. After messing around I came up with the following: 
$(document).ready(function() {
$.getJSON("/Person/GetPerson/", { id: 4 }, function(data) {
This took me five minutes to get right (which JQuery method? -> Google, how to pass data? -> find example, plus a typo in the first/First member). Five minutes of stupid getting right what should be trivial. Why not let the compiler help? So using Weld I change my server side method to this :
public JsonResult<Person> GetPerson(int id)
return new JsonResult<Person>(Json(new Person
First = "Barack",
Last = "Obama"
}, JsonRequestBehavior.AllowGet)); ;
Basically I wrap my JsonResult in a generic wrapper JSonResult<T> (included with Weld) so that Weld knows what type to expect. Next I add the AjaxMethod Weld attribute. Client side I use TypeScript and use the generated proxy class.  
/// <reference path="Weld/PersonController.ts" />/// <reference path="typings/jquery/jquery.d.ts" />
$(document).ready(function () {
PersonController.prototype.GetPerson(2, (person) => {
Now person is a JavaScript object or a TypeScript 'any' type. No, Person is a fully defined TypeScript interface with a First and Last member just like my C# class. Here's the generated code:
/// <reference path="../typings/jquery/jquery.d.ts" />
class PersonController
GetPerson(id: number, callback: (data: Person) => any)
var url = "/Person/GetPerson";var data = { id: id };
url: url,
type : "POST",
data: data,
success: callback,
interface Person
First: string;
Last: string;
As always in the end there is still JavaScript code generated which you can easily debug. Weld code is simple and clean. Easy huh? And there are more benefits:
  1. If I remove or rename my action-method the TypeScript compiler will detect my breaking client side code at compile time. If you just use javascript you will (hopefully) find out at runtime.
  2. If I add or remove properties from my Person class my changes will cascade to the clientside immediately. 
  3. I get a nice interface clientside making code completion really work 
  4. No more Googling JQuery methods
  5. This is more DRY (Don't Repeat Yourself). For example if you don't like JQuery you can build a Weld template using a different method. Regenate and you are ready
Weld is fully open source and can be found at

wagner 7/12/2013 8:01:13 PM #

it's wrong

Merlyn Namanworth 8/31/2013 7:47:52 PM United States #
Merlyn Namanworth

I have recently started a web site, the info you offer on this website has helped me tremendously. Thank you for all of your time & work.

Laila Lacorte 9/3/2013 4:53:18 PM United States #
Laila Lacorte

At least Obama is asking Congess for approval before he strikes in the latest round. I understand that may not be what you are talking about but It is certainly relevant.

Roxann Wallack 9/11/2013 3:25:24 PM United States #
Roxann Wallack

Has anybody had a positive experience using the Fullerton Drake Medical center Weight Reduction program?

Copper Jewelry 10/4/2013 3:48:26 AM United States #
Copper Jewelry

Hello! I�ve been reading your web internet site for a even though now and finally got the courage to go ahead and give you a shout out from  Kingwood Texas! Just wanted to say keep up the good work!

Handmade Jewelry 11/2/2013 1:58:51 AM United States #
Handmade Jewelry

Billiard is really a game which is mostly played by the high class men and women

Handmade Jewelry 11/6/2013 6:15:55 AM United States #
Handmade Jewelry

New to your blog. Stumbled upon it browsing the internet. Keep up the excellent work. I'm hoping you update it regularly.

Handmade Jewelry 11/11/2013 3:15:03 AM United States #
Handmade Jewelry

Seriously, what a blog! I mean, you just have a fantastic deal of guts to go forward and tell it like it truly is. You happen to be what running a weblog need to have, an open minded superhero who isn’t frightened to tell it like it's. This really is certainly something people require to be up on. Good luck inside the foreseeable future, man.

My Favorite 11/12/2013 8:05:35 AM United States #
My Favorite

I need to to take the time and write to you that you have certainly helped us simply by creating this amazing posts. I was happy to follow your own subsequently helpful facts and put it to some fantastic use. I would really like to convey my gratitude and would like to tell your followers they are so fortunate to have someone like you creating fantastic material. I anticipate studying much more useful content like this from you down the road. Once more, thank you so much so much with the extremely helpful post. We have added your rss feed as well as book-marked you web site in my social bookmarking web site. Cheers!

call center jobs 11/13/2013 12:46:42 PM United States #
call center jobs

bonjour je suis un �tudiante de la portugal j'ai trop aimer ton site puis les couleurs extraordinairement sur l'article la site . R�ellement merci pour l'gouverneur de ce online site

call center job postings 11/13/2013 12:51:40 PM United States #
call center job postings

bonjour je suis un petit �tudiante de la france j'ai trop aimer votre implacable web page ainsi les colorations extraordinairement sur l'article la site . Vraiment merci pour l'dirigeant fuente ce blog

Santa letters 12/4/2013 5:41:26 PM United States #
Santa letters

My coder is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the expenses. But he's tryiong none the less. I've been using Movable-type on various websites for about a year and am concerned about switching to another platform. I have heard excellent things about Is there a way I can transfer all my wordpress posts into it? Any help would be greatly appreciated!

Letter From Santa 12/6/2013 7:48:33 AM United States #
Letter From Santa

Hey there! Quick question that's entirely off topic. Do you know how to make your site mobile friendly? My blog looks weird when viewing from my iphone 4. I'm trying to find a theme or plugin that might be able to resolve this problem. If you have any recommendations, please share. Appreciate it!

Buddy Dinnendahl 12/14/2013 9:18:13 PM United States #
Buddy Dinnendahl

Simply want to say your article is as amazing. The clearness for your put up is simply nice and that i could think you're knowledgeable on this subject. Well with your permission allow me to grab your feed to stay up to date with drawing close post. Thanks a million and please continue the enjoyable work.  <a href=>how to remove pimples</a>

Xavier Koda 12/15/2013 6:26:11 AM United States #
Xavier Koda

Nice post. I used to be checking constantly this weblog and I am impressed! Extremely useful information specifically the final part Smile I maintain such information a lot. I was looking for this particular information for a long time. Thanks and best of luck.   <a href=>asthmatic bronchitis</a>

Darell Tretina 12/15/2013 4:27:44 PM United States #
Darell Tretina

Hello, I log on to your blog regularly. Your humoristic style is awesome, keep doing what you're doing!  <a href=>how to get rid of cellulite</a>

Felix Roton 12/15/2013 9:10:38 PM United States #
Felix Roton

Hello, yeah this article is truly fastidious and I have learned lot of things from it about blogging. thanks.  <a href=>credit repair</a>

Gregg Doubet 12/16/2013 2:22:21 AM United States #
Gregg Doubet

I got this website from my buddy who told me regarding this site and at the moment this time I am visiting this site and reading very informative content at this time.  <a href=>cancer treatment</a>

ATT UVERSE 12/20/2013 2:49:22 AM United States #

Valuable information. Lucky me I found your web site unintentionally, and I'm shocked why this twist of fate did not came about in advance! I bookmarked it.

Willena 12/24/2013 12:39:40 PM United States #

My research has been enhanced by you information, I'm thankful for the post

personal injury lawyers austin 1/1/2014 7:44:01 PM United States #
personal injury lawyers austin

content. I cherished your post! The place am i able to obtain out a lot more details about this? Is it alright to put element of the on my particular blog site if I submit a reference level to this webpage? Awesome article, many thanks, I will bookmark you now! Is it okay to location portion of this in my personal webpage if perhaps I submit a reference to this world-wide-web web-site? Indeed it's ok. This actually answered my dilemma, thanks! A insightful article there mate . Thanks for that ! I really like that website format . How do you help it become!? Its really interesting. Dude. This blog site is neat! How does one allow it to be search this great . It appears to me this world-wide-web internet site doesnt load up on a Motorola Droid. Are other people having precisely the same dilemma? I enjoy this site and dont wish to have to miss it any time Im absent from my computer. Have you ever considered including a couple of social bookmarking links to these blogs. In the pretty least for bebo. Have not imagined of that. Any Strategies on how to go about it? This truly answered my difficulty, thank you! In the event you dont thoughts, wherever do you host your weblog? I am looking for the superior internet host and your webpage appears to become particularly fast and up just about every one of the time I use hostgator Just to permit you know your web site seems to be a little bit unusual on Safari on my pc with Linux . It appears to be to me that this web site doesnt load on a Motorola Droid. Are other folks having the exact exact situation? I enjoy this webpage and dont wish to have to miss it when Im absent from my computer. Have you considered incorporating some differing opinions towards the article? I do think it will genuinely enhance viewers knowledge. This weblog web page is excellent. How did you enable it to be ? I purchased an book on world wide web designing and that i follows the step by step outline within. It is actually incredibly easy to utilize as I do not even know HTML. A appealing blog site article correct there mate . Thanks for submitting ! Just identified this page thru Yahoo, what a pleasant shock! Just identified this web site thru Google, what a pleasant shock! Desired to drop a remark and enable you realize your Feed is not functioning today. I tried introducing it to my Google reader account and got certainly absolutely nothing. Thanks for the observation but I have not but set up a feed for this site very handy stuff, total I picture this can be worthy of a bookmark, thanks If you could information me having a several hints & suggestions on how you manufactured your blog site web site glance this awesome, Id be appreciative. The appear for your internet site can be a tad off in Epiphany. Even So I like your site. I may well really need to set up a normal browser just to enjoy it. Have you ever assumed about incorporating some relevant links to the report? I do think it will really enhance viewers comprehending. Have you considered introducing some videos into the article? I think it will definitely enhance everyones knowing. I've not believed of that. Any Idea? Have you considered including some social bookmarking links to these websites. At the extremely least for bebo. Have not thought of that. Any Tips on it? This website web page has some definitely practical info on it! Cheers for helping me. I like your wordpress net template, exactly where did you get yourself a hold of it? Nice put up ! Cheers for, commenting on my blog webpage gentleman. Ill message you some time. I didnt realize that! As soon as I originally commented I clicked around the Notify me whenever new opinions are additional checkbox and now each time a comment is extra I receive 4 emails using the identical comment. When i start your Feed it appears to generally be being a great deal of garbage, will be the issue on my side? I enjoy your wordpress template, in which did you get yourself a hold of it? I downloaded it from the world wide web working with google lookup engine Hello just wished too provide you with a quick heads up. Thee terms within your

acne scars 1/13/2014 7:39:33 PM United States #
acne scars

I enjoy what you guys are usually up too. This kind of clever work and exposure! Keep up the amazing works guys I've included you guys to  blogroll.  <a href=>best acne treatment</a>

Legginsy 1/16/2014 1:14:17 PM United States #

Outstanding post, you have pointed out some  superb  points , I  besides   conceive this s a very  great  website.

the original source 1/19/2014 10:35:07 AM United States #
the original source

I gotta bookmark  this  web site  it seems  extremely helpful  extremely helpful

pipe tobacco 1/23/2014 2:24:12 AM United States #
pipe tobacco

Hi there cos i so totally love your great site, i wuold be happy if i could write a long review about this wordpress blog on my would you say yes?

voyance gratuite immediate 1/24/2014 12:24:37 AM United States #
voyance gratuite immediate

logiciel horoscope gratuit de marseille<br/>Visiter notre superbe site web : <a href="">voyance gratuite en direct</a>

voyance gratuite immediate 1/24/2014 5:53:18 AM United States #
voyance gratuite immediate

lire tarot par telephone toulouse<br/>Decouvrir notre nouveau post : <a href="">voyance</a>;

Nidia 2/6/2014 3:26:55 PM United States #

Will love to read more from you in the future, keep the good stuff coming.

voyance gratuite en ligne 2/8/2014 10:59:59 AM United States #
voyance gratuite en ligne

logiciel voyance par mail nice<br/>Decouvrir mon excellent site web : <a href="http://www.paradiseradio;fr">voyance par telephone gratuite</a>

voyance sans attendre 2/8/2014 11:10:27 AM United States #
voyance sans attendre

voyance par telephone amour ile de france<br/>Voir notre excellent site web : <a href="">voyance gratuite en direct</a>

voyance immediate aujourd'hui 2/8/2014 12:57:36 PM United States #
voyance immediate aujourd&#39;hui

voyance par telephone  de marseille<br/>Voir mon superbe blog : <a href="http://www.paradiseradio;fr">voyance par telephone gratuite</a>

amoureuse voyance 2/9/2014 4:21:23 PM United States #
amoureuse voyance

voyance par telephone amour ile de france<br/>Visiter notre excellent blog : <a href="">voyance</a>;

Cette voyance 2/10/2014 10:45:45 PM United States #
Cette voyance

voyance gratuite  de marseille<br/>Decouvrir ce nouveau blog : <a href="http://www.paradiseradio;fr">voyance en direct</a>

atomiseur ego-t 2/11/2014 11:47:01 AM United States #
atomiseur ego-t

Consulter notre excellent site : <a href="">Acheter cigarette ego-t</a><br/>

ekonomia 2/17/2014 12:39:51 PM United States #

Great information. Lucky me I came across your site by accident (stumbleupon). I have saved as a favorite for later! 2/17/2014 4:39:11 PM United States #

Wonderful points altogether, you simply gained a logo new reader. What would you recommend about your put up that you simply made some days in the past? Any positive?

brazil world cup 2002 squad 2/20/2014 9:47:59 PM United States #
brazil world cup 2002 squad

Portugal is at the moment rated four th in the FIFA standings, and with great cause. With stars these kinds of as Cristiano Ronaldo and Simao, you know they're in for a deep World Cup run for 2010. World Cup heritage has not been way too sort to the Portuguese with their best end coming in 1966 at three rd In 2006, Portugal finished 4 th, which may possibly have appeared limited of expectations. You know how a volcano lies dormant just before it erupts? That's the comparison I like to use for Portugal. The quarter finals will be held on 4 and five July. As properly as, semi finals will be held at eight and 9 July.|With their Spanish-dependent player Maradona, the men's soccer staff of Argentina failed to advance the semis soon after shedding (two-one) to eventual winner Italy and then with Brazil (3-one) in the 2nd spherical. Whilst the obvious-lower loser of the Spanish tournament was Brazil, curiously a soccer-loving nation that has by no means won a gold medal in men's football at the Olympic Summer Video games in contrast to Italy, Mexico, Uruguay, Argentina, and Nigeria. Nevertheless regardless of not profitable the FIFA World Cup, the 1982 Brazilian contingent was regarded as a single of the twentieth century's most fantastic teams. Socrates was Brazil's 1982 World Cup captain.But there ended up other interesting specifics.

free iphone application 2/22/2014 1:10:12 AM United States #
free iphone application

nice share,Thanks for the informations dont forget to drop by my link and apply to be able to win a free iphone 5c

crystal 2/23/2014 6:42:16 AM United States #

The post was genuine helpful for my research, ideally I can discover more similar details

sites 2/24/2014 6:07:31 AM United States #

obviously like your website but you have to test the spelling on quite a few of your posts. A number of them are rife with spelling problems and I to find it very bothersome to inform the truth then again I'll surely come back again.

Carlos Nosacka 2/25/2014 12:45:17 PM United States #
Carlos Nosacka

Hey There. I found your blog using msn. This is a really well written article. I'll make sure to bookmark it and come back to read more of your useful information. Thanks for the post. I'll definitely return.

Katelyn 3/1/2014 12:01:43 AM United States #

Thanks for your input, it help me immensely

Pamala 3/2/2014 2:53:47 AM United States #

Nice work your blog is a great resource, especially for my research

Viviana 3/3/2014 8:46:23 PM United States #

I like what you have done here, please keep providing stella information.

Lashell 3/5/2014 9:49:08 AM United States #

My research has been enhanced by you information, I'm thankful for the post

engagement rings 3/6/2014 12:17:12 AM United States #
engagement rings

Hopefully I can come back and use more of your information, thanks for posting.

web-site 3/12/2014 1:22:51 AM United States #

I like this web site very much, Its a very nice office to read and find info. "We are all failures--at least, the best of us are." by James Barrie.

tootpaste 3/22/2014 1:06:08 PM United States #

I was just browsing, your post has actually been worth the search

visit page 4/21/2014 5:11:24 AM United States #
visit page

Regards  for helping out,  wonderful  information.

chatline 5/16/2014 4:06:00 AM United States #

Enjoyed reading  this, very good stuff, thanks . "Curiosity killed the cat, but for a while I was a suspect." by Steven Wright.

this astrology site 5/23/2014 3:20:19 PM United States #
this astrology site

Thankyou  for helping out,  excellent  info .

Facehook 6/13/2014 9:29:55 PM United States #

Social marketing is a jungle, and you better learn to pimp your own profiles.

Become Popular 6/14/2014 10:53:12 PM United States #
Become Popular

Our mutual interest is obvious. Splendid!

snipping tool 6/15/2014 5:25:22 PM United States #
snipping tool

This was a fantastic read. Thank you for sharing it around! Nowadays the world wide web is full of poor content however, there is no doubt that you just spent long by editing the information. Again, appreciate your time as well as for your efforts!

The Art of Grabbing Attention 6/16/2014 1:38:18 PM United States #
The Art of Grabbing Attention

Hooray. A number of these methods are not on our list. Splendid.

Pantofi Barbatesti 6/18/2014 12:43:45 PM United States #
Pantofi Barbatesti

Simply because I initially wrote concerning MBT sneakers at <strong><a href=""; title="Pantofi Barbatesti">Pantofi Barbatesti</a></strong>, a ton includes improved more than the brand name, and the inventor and founder consists of still left the enterprise. Between true prospective buyers, testimonials of MBT footwear are pretty put together. If by yourself're thinking about a few of MBT sneakers, I strongly really encourage by yourself towards as well examine the opinions still left within answer toward the immediately after article content, and discuss towards your health practitioner just before putting on any design of shoe that is hence drastically option towards what on your own're made use of toward, or towards deal with any style of suffering or difficulty.

Kosiarki ceny 7/15/2014 8:37:36 AM United States #
Kosiarki ceny

It�s actually a nice and useful piece of information. I am glad that you shared this helpful info with us. Please keep us up to date like this. Thanks for sharing.

Dropbox Tips Tricks 4/29/2015 4:29:36 AM United States #
Dropbox Tips Tricks

After looking at a few of the blog posts on your web page, I seriously like your technique of writing a blog. I added it to my bookmark webpage list and will be checking back soon. Please check out my web site too and let me know how you feel.

bateria iphone 5/29/2015 9:43:38 AM United States #
bateria iphone

<p>999 A vital section of every woman wardrobe are her sneakers.<br /> <a href=""; rel="nofollow">cheap louis vuitton wallets</a></p>

Carroll B. Merriman 6/9/2015 5:48:34 PM United States #
Carroll B. Merriman

Czy mo�na upiec ciasto bez m�ki? Mo�na! A bez jajek? Te� mo�na! Ciasto powsta�o specjalnie dla mojej starszej c�ry, kt�ra ma uczulenie na bia�ko jaja kurzego i czeka na badanie w kierunku celiakii st�d te� od oko�o roku w naszym domu cz�stym go�ciem s� produkty bezglutenowe. Dodatkowo mamie zachcia�o si� zosta� wegank�, ale kocha smak czekolady, tato te� uwielbia s�odycze, m�odsza siostrzyczka te� ch�tnie li�nie, tak wi�c jest tou nas ciasto idealne dla ka�dego. No i przygotowuje si� je bez u�ycia miksera, bez brudzenia miliona gar�w i potrafi je przygotowa� (z ma�� pomoc�) moja 3-letnia c�rka. Tak�e serdecznie zach�cam do spr�bowania, bo naprawd� warto! Panie i Panowie: Czekoladowe, bezglutenowe vege-ciasto.Wi�cej informacji na moim blogu

Milagros Muina 6/12/2015 10:30:21 PM United States #
Milagros Muina

This really is the worst write-up of all, I’ve study

pleasant 6/23/2015 7:58:21 PM United States #

Amazing what you can come across

Kirk Tripoli 6/26/2015 10:59:14 AM United States #
Kirk Tripoli

Really good blog, thank you so much for your effort in writing the post.

Marco 7/10/2015 2:47:25 AM United States #

Hi everybody, I'm an Italian man decided to send a message which will describe my personality. Long ago there were transmitted values by GOD and JESUS, and at that time people felt it more consideration. Nowadays, the observance of these principles has started a process of decay. This consideration of the values is not only vital in personal relationships between men and women, but also towards present and future society, which learns and will learns our behaviour patterns. All this means that the more time passes, the less importance has the lives of others. A couple must have a very strong faith in order to address all the problems that life delivers, so it is necessary that each other are offset by a fidelity that is based precisely on the concepts above. IT'S ESSENTIALS THAT ALL PEOPLE DIFFUSE THE GOSPEL ALL OVER THE WORLD AS MANY PEOPLE WE CAN. My main characteristic is focused on being God-loving, for this reason i'm very reliable in relationships. Nobody is perfect, but this particular side makes safer a person who is interested to become a part of my life. I am willing to start something special that will lead to the development of a more solid bond. I'm available to relocate everywhere because for me geographical distance is purely a matter of jumping on a plane and next second virtual world became reality. Whatsapp: +447937463555; Viber: +393409282577; skype: testifi87

free mp3 download 7/16/2015 8:18:51 PM United States #
free mp3 download

Finding music that is both free and legal to download isn't always easy. ...

solar panels australia 7/23/2015 12:22:23 PM United States #
solar panels australia

I tried viewing your site on my iphone and the design does not seem to be correct. Might want to check it out on WAP as well as it seems most mobile phone layouts are not working with your web site.

unique bikinis 7/28/2015 11:36:24 PM United States #
unique bikinis

I've been absent for some time, but now I remember why I used to love this web site. Thank you, I'll try and check back more frequently. How frequently you update your site?

Agua Bendita Quetzal 7/29/2015 12:04:13 AM United States #
Agua Bendita Quetzal

bikini bottom 7/29/2015 3:23:00 AM United States #
bikini bottom

agua bendita veracruz 7/29/2015 3:27:25 AM United States #
agua bendita veracruz

agua bendita swim 7/29/2015 9:18:17 AM United States #
agua bendita swim

agua bendita limited edition 7/29/2015 11:10:27 AM United States #
agua bendita limited edition

I dugg some of you post as I thought  they were  extremely helpful  invaluable

Agua Bendita Acrobacia 8/6/2015 12:19:53 PM United States #
Agua Bendita Acrobacia