I want to check the data is valid or not
public ActionResult ValidCheck(student model)
{
Models.ViewModel.User model = new Models.ViewModel.User();
model.Age = 12;
model.Name = "Andy He";
model.Email = "123";
//TryValidateModel(model);
}
could you help me?
Aryan Kumar
18-Jun-2023Sure, here are the steps on how to manually check if a model is valid or not in MVC:
Here is an example of how to manually check if a model is valid or not in MVC:
C#
This code will create a controller action that checks the validity of the IndexModel model. If the model is not valid, then the action will render the Index view. Otherwise, the action will redirect to the Success action.
The ModelState object is a dictionary that contains the validation errors for the model. The ModelState.IsValid property is a Boolean property that indicates whether the model is valid or not. If the ModelState.IsValid property is true, then the model is valid. Otherwise, the model is not valid.
Anonymous User
29-Apr-2018try this code hope it resolve your problem