welcome to my blargh

now with 88.333% more desu. repeating of course.

Anonymous types and System.Web.Mvc.JsonResult issue?

Wow, this is driving me utterly insane. Take a look at the two versions of this code:

Pretty simple right? I left out some stuff for brevity, but I have a very simple subclass defined called JsonJob into which I copy the properties from the Linq Object.

Version 2:

So, more brief. Selects data using Linq, returns an anonymous type which I push out as a JsonResult.

Technically these two should work the same way. Why does Json() care about type? But it seems that for me, anonymous types create malformed Json or something. Here's my AJAX request using jQuery:

Again, pretty simple. But if I use Version 2, the error callback is triggered every time (with no error defined!).

Of course everyone says This Doesn't Happen For Me (tm), but that's no help.

Loading mentions Retweet

Filed under  //   asp.net mvc   programming  
Posted September 25, 2009
// 1 Comment

Some daily notes on learning ASP.NET MVC

- You don't need a view for every controller action. For instance you can return a JsonResult for Ajax requests.

 
- When using jQuery to post AJAX requests, it's easiest to use $.getJSON because it automatically creates the JSON object for you. Otherwise you can use: var x = Eval(data); to get a hold of a json object.
 
- Very low need for custom routes so far, unlike other MVC frameworks I've used. The default seems to work fine for most needs.

- Data can be returned to a page two ways: Through ViewData collection (good if you have multiple sources of data), or through the Model.

 
- View Data needs to be cast to it's proper type before you use it. Makes things sort of messy.
 
- Return data to the model via 'return View(object);' in the controller. Make sure to modify the Inherit declaration at the top of the view: "System.Web.Mvc.ViewPage<List<MvcApplication1.Data.Job>>".

Loading mentions Retweet

Filed under  //   asp.net mvc   programming  
Posted September 24, 2009
// 0 Comments