Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Model Binding WepApi2 is allways null

$
0
0

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?


Viewing all articles
Browse latest Browse all 4850

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>