Last post Jan 15, 2014 02:28 AM by miparejo
Member
2 Points
7 Posts
Jan 15, 2014 02:05 AM|ChrisPDX503|LINK
I have a model class:
public class CheckUserEmail { [Required] [Display(Name = "Email Address")] [DataType(DataType.EmailAddress)] [EmailAddress] public string Email { get; set; } }
And the following method in an API Controller
public string Get(CheckUserEmail model) { return model.Email; }
Going to domain/api/Test/?Email=bla@bla.com the model is null?
Yet the following method in an MVC controller works just fine ie going to domain/home/test/?Email=bla@bla.com and the model is not null
public ActionResult Test(CheckUserEmail model) { return View(model); }
With the following view:
@model MainAppWebRole.Models.CheckUserEmail @Model.Email
Why is the WebApi2 not binding the get values to the model, but MVC is?
40 Points
14 Posts
Jan 15, 2014 02:28 AM|miparejo|LINK
Hi,
Check you WebAPI configuration
Ceck API Controller inherits from ApiController
Finally try decorating Api Get method with HttpGet attribute
Hope it helps
Miquel
Member
2 Points
7 Posts
Model Binding WepApi2 is allways null
Jan 15, 2014 02:05 AM|ChrisPDX503|LINK
I have a model class:
And the following method in an API Controller
Going to domain/api/Test/?Email=bla@bla.com the model is null?
Yet the following method in an MVC controller works just fine ie going to domain/home/test/?Email=bla@bla.com and the model is not null
With the following view:
Why is the WebApi2 not binding the get values to the model, but MVC is?
Member
40 Points
14 Posts
Re: Model Binding WepApi2 is allways null
Jan 15, 2014 02:28 AM|miparejo|LINK
Hi,
Check you WebAPI configuration
Ceck API Controller inherits from ApiController
Finally try decorating Api Get method with HttpGet attribute
Hope it helps
Miquel