WebAPI – Accepting both form data and query string parameters

Recently, I had to write a WebAPI method in C# that would be an HTTP POST.  Basically, I wanted to hit


and pass a bunch of data in the body of the request. Simple, no?

In our project, we make heavy use of the Route attribute to decouple the method name from the URL.  My method looked okay.

    public class DemoController : ApiController
        public IHttpActionResult Sample([FromBody] string requestBody, string id)
            return Ok(String.Format("Request with ID {0} body has a length of {1}", id, requestBody.Length));

This sample code is clearly very simple.  I have decoupled the controller to api-demo and the method to samplemethod. It appears like everything would work as expected, however when I would test it via POSTMAN, I get the following response:

  "$id": "1",
  "Message": "No HTTP resource was found that matches the request URI 'http://localhost:99/api-demo/samplemethod/1134630'.",
  "MessageDetail": "No type was found that matches the controller named 'api-demo'."

Read more

Ajax forms and PartialViews opening in a new page

Why can’t this just work the way it’s supposed to out of the box?

So here’s today’s dilemma (which I’ve solved exactly once for each project I’ve done because once it’s done you don’t have to redo it which makes me think ‘gee… maybe it should be this way to start off with’).  When you have a form on your page and want to submit it and get a result via Ajax the results are being displayed on a new page, not in the output div you specified. Read more

ASP.Net the new Ruby on Rails?

Wow… I’m just watching this video about how the Model/View/Controller design pattern is going to be implemented in ASP.Net and VB.Net. As many of you know, I enjoy working on and with Ruby on Rails. RoR is entirely based on the MVC design pattern. It’s surprising to me just how similar the ASP.Net implementation of it is.

Considering the benefits of MVC, it’s surprising that Microsoft hasn’t implemented it so rigorously before. Nonetheless, I’m glad to see that they will finally be releasing it. As to the title of the post, the MVC architecture makes a LOT of sense in terms of the web. When we look at the market penetration of VB.Net and ASP.Net versus RoR, it’s clear who the winner is. We, the developers, are!
I don’t really think that Microsoft implementing MVC poses any real threat to RoR. In fact, Ruby on Rails may actually benefit from more people knowing about and being comfortable with it.
Scroll To Top