You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an action-method that have an object type Input like this:
public async Task<IActionResult> DoSomeThing([FromBody]object input, bool options)
{
if (options == true)
{
var castedInput = (A) input;
if (TryValidateModel(castedInput))
{
// do some thing
}
else
{
//return validation Errors;
//forexample:return Error("Error1")
//??!??!!??!?!?!?!??!
}
}
else
{
var castedInput = (B)input;
if (TryValidateModel(castedInput))
{
// do some thing
}
else
{
//return validation Errors;
//forexample:return Error("You must fill this parameter")
//??!??!!??!?!?!?!??!
}
}
}
In this method first I cast Input to my ViewModel then validate it. now I want to return my Validation Errors that I set on annotations of my model.
How can I do this?
My Viewmodels:
public class A
{
[Required(ErrorMessage = "Error1")]
string Phone;
.
.
.
}
public class B
{
[Required(ErrorMessage = "You must fill this parameter")]
string Name;
.
.
.
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have an action-method that have an
object type
Input like this:In this method first I cast Input to my ViewModel then validate it. now I want to return my Validation Errors that I set on annotations of my model.
How can I do this?
My Viewmodels:
Beta Was this translation helpful? Give feedback.
All reactions