1

Using the F# MVC 5 Visual Studio extension and it works perfect for GET requests. However, I'm getting a No parameterless constructor defined for this object error when trying to perform a POST.

Here's the method in the HomeController:

[<HttpPost>] 
member this.Edit product =
    Products.updateProduct product

    this.RedirectToAction("Index")

Here's the Product type it's using where I guess the problem is originating:

type Product = {
  ProductId: int
  ProductName: string
  ProductCount: int
  ProductPrice: string
}

Is it possible to fix this within the type or is there something else I'm missing?

Jon
  • 2,644
  • 1
  • 22
  • 31
  • 6
    Adding the `[]` attribute to `Product` might do the trick. – Daniel Mar 15 '16 at 21:30
  • 1
    @Daniel That worked! Feel free to put it as an answer and I'll accept. If you can, perhaps you can give a quick reason to why that's needed? Thanks! – Jon Mar 15 '16 at 22:11
  • Related: http://stackoverflow.com/a/22789985/126014 Explanation: http://blog.ploeh.dk/2013/10/15/easy-aspnet-web-api-dtos-with-f-climutable-records – Mark Seemann Mar 15 '16 at 22:42
  • See also http://blog.ploeh.dk/2015/03/19/posting-json-to-an-f-web-api – Mark Seemann Mar 15 '16 at 22:43
  • Thanks for the extra info, @MarkSeeman! Curious, though, since it compiles to an internal mutable type, do you still have the immutability of the F# type in your code? – Jon Mar 16 '16 at 01:47
  • Yes, to F# it still looks immutable. That's the whole point :) – Mark Seemann Mar 16 '16 at 05:55
  • Thanks again, @MarkSeemann! Makes much more sense now. :] – Jon Mar 16 '16 at 13:46

0 Answers0