-
Notifications
You must be signed in to change notification settings - Fork 33
IbanNet.DataAnnotations
skwas edited this page Dec 11, 2019
·
17 revisions
The IbanNet.DataAnnotations
package provides support to validate IBAN user input with Microsoft DataAnnotations.
public class InputModel
{
[Iban]
public string BackAccountNumber { get; set; }
}
// MVC
public class MyMvcController : Controller
{
[HttpPost]
public ActionResult Save(InputModel model)
{
if (ModelState.IsValid)
{
// ..
}
}
}
// Web API
public class MyWebApiController : ApiController
{
[HttpPost]
public IHttpActionResult Save(InputModel model)
{
if (ModelState.IsValid)
{
// ..
}
}
}
public class MyController : Controller
{
[HttpPost]
public ActionResult Save([Iban] string bankAccountNumber)
{
if (ModelState.IsValid)
{
// ..
}
}
}
The System.ComponentModel.DataAnnotations.ValidationContext
provides an IServiceProvider
for resolving dependencies. IbanNet uses this to resolve an IIbanValidator
which is then used to validate the user input. If no instance of IIbanValidator
is resolved from the DI container, the static Iban.IbanValidator
property is used instead.
For more detailed info please visit: