0

According to the documentation, the model validations for Apis can be done something like this:

public IActionResult Use(Batman batman)
{
    if (ModelState.IsValid) return Ok();
    return BadRequest(ModelState);
}

Or for .net core 2.1,

public IActionResult Use(Batman batman) => Ok();

This produces a response something like this:

{
    "Alias": [
        "The Alias field is required."
    ],
    "FamilyName": [
        "The FamilyName field is required."
    ]
}

Where Alias and FamilyName are properties in Batman.

Is there a built-in way for xamarin forms to use this output? Some way in which, after consuming the api, if the response were 400, the errors are directly printed on xamarin forms page. Basically the xamarin forms equivalent of the following .net core code:

<input asp-for="Alias" /> 
<span asp-validation-for="Alias"></span>

I am aware of the third party tools that do this, and the custom ways such as creating a Behavior for the components. However, I am trying to find out if xamarin forms have something built in for this. Considering how much we can do with .net core tag helpers, I was expecting a similar first party solution on xamarin.forms as well.

Neville Nazerane
  • 6,622
  • 3
  • 46
  • 79
  • You want to validate user input, or requests from the API? – Bruno Caceiro Jul 02 '18 at 15:30
  • if the API responds with a "bad request", I am looking for a built-in way to print the errors on xamarin froms's page – Neville Nazerane Jul 02 '18 at 16:13
  • side note: since I posted this question, I have been working on a project to address this feature: https://github.com/neville-nazerane/NetCore-Apis. Can't post it as an answer since it is a third party solution. But this may help someone who might be trying the same – Neville Nazerane Aug 28 '18 at 02:47

0 Answers0