mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 18:11:36 +01:00
21 lines
679 B
C#
21 lines
679 B
C#
using System;
|
|
using System.Linq.Expressions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
|
|
|
namespace BTCPayServer
|
|
{
|
|
public static class ModelStateExtensions
|
|
{
|
|
public static void AddModelError<TModel, TProperty>(this TModel source,
|
|
Expression<Func<TModel, TProperty>> ex,
|
|
string message,
|
|
ControllerBase controller)
|
|
{
|
|
var provider = (ModelExpressionProvider)controller.HttpContext.RequestServices.GetService(typeof(ModelExpressionProvider));
|
|
var key = provider.GetExpressionText(ex);
|
|
controller.ModelState.AddModelError(key, message);
|
|
}
|
|
}
|
|
}
|