Write in front
Submitting forms in development and validating the values of forms is a very common operation, and ANGULARJS provides very good support for form validation.
Demo
Form
<formname= "MyForm"novalidate Action=".. /api/order/lists/add "Method= "POST"> <P> <inputtype= "text"name= "Name"Ng-model= "Order.name"value=""Required/> <spanstyle= "Color:red"Ng-show= "Myform.name. $dirty && myform.name $invalid"> <spanNg-show= "Myform.name. $error. Required">The order name is required.</span> </span> </P> <P> <inputtype= "text"name= "Price"Ng-model= "Order.price"value=""Required/> <spanstyle= "Color:red"Ng-show= "Myform.price. $dirty && myform.price $invalid"> <spanNg-show= "Myform.price. $error. Required">The unit price is a must.</span> </span> </P> <inputtype= "Submit"name= "Name"ng-disabled= "Myform.name. $dirty && myform.name $invalid | | Myform.price. $dirty && myform.price. $invalid " /></form>
Service side
[HttpPost] [Route ("Api/order/lists/add")] Public AsyncTaskPost ([frombody] order order) {return awaitTask.Factory.StartNew (() ={httpresponsemessage response=Newhttpresponsemessage (httpstatuscode.accepted); Order. Id=Guid.NewGuid (); Lstorders.add (order); Response=NewHttpresponsemessage (httpstatuscode.accepted) {Content=NewStringcontent (Jsonconvert.serializeobject (New{_code = $, _data =lstorders})) }; returnresponse; }); }
Test
Post-submission Data
Summarize
$dirty: The form is filled with records
$valid: Field contents are valid
$invalid: Field contents are illegal
$pristine: The form does not fill in records
[Angularjs] Form validation