Viewed 26 times
This example demonstrates the code that is used to post the JSON data to the server using AngularJS $http service based on AJAX POST protocol. Angularjs serialize form data. Ask Question up vote 5 down vote favorite. How to create json object for html form using AngularJS? JavaScript post request like a form submit. Serializing to JSON in jQuery. Convert form data to JavaScript object with jQuery.
I have a form that has some data and a feature of selecting multiple files may be file by file or multiple files at once or combination of them and send the request to my API but if i make my post action has a model parameter and i want the request hits the action and bind data to my model but it doesn't hit the action at all and gives me
![Angularjs Angularjs](/uploads/1/2/6/2/126217255/667980965.png)
Angularjs Form Template
500 internal server error
and this exception:
{'Message':'An error has occurred.','ExceptionMessage':'Error getting value from 'ReadTimeout' on 'Microsoft.Owin.Host.SystemWeb.CallStreams.InputStream'.','ExceptionType':'Newtonsoft.Json.JsonSerializationException','StackTrace':' at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)rn at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)rn at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)rn at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)rn at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)rn at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)rn at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)rn at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)rn at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)rn at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)rn at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)rn at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)rn at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)rn at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)rn at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)rn--- End of stack trace from previous location where exception was thrown ---rn at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()rn
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at System.Web.Http.Owin.HttpMessageHandlerAdapter.d__27.MoveNext()','InnerException':{'Message':'An error has occurred.','ExceptionMessage':'Timeouts are not supported on this stream.','ExceptionType':'System.InvalidOperationException','StackTrace':' at System.IO.Stream.get_ReadTimeout()rn at GetReadTimeout(Object )rn at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)'}}
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)rn at System.Web.Http.Owin.HttpMessageHandlerAdapter.d__27.MoveNext()','InnerException':{'Message':'An error has occurred.','ExceptionMessage':'Timeouts are not supported on this stream.','ExceptionType':'System.InvalidOperationException','StackTrace':' at System.IO.Stream.get_ReadTimeout()rn at GetReadTimeout(Object )rn at Newtonsoft.Json.Serialization.DynamicValueProvider.GetValue(Object target)'}}
My form view like that:
I send the form data with files from angularJs service like that:
API Controller definition:
AnnouncementVM Model:
My sent request:
georgeawg38.8k1111 gold badges5757 silver badges7474 bronze badges
Asmaa RashadAsmaa Rashad
Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.
Browse other questions tagged c#angularjsapiserialization or ask your own question.
Active4 years, 2 months ago
Trying to understand how could be possible to write a function, (directive / controller) that would transform all my
form inputs
to json with current value that they have to json
. The json would have a format similar to that:
Where to start from at least.. with no
sessesjquery
applying?6,9762222 gold badges9797 silver badges180180 bronze badges
1 Answer
ng-model
does it for you. A scope variable will be created if you haven't already created it yourselfIf you have the object to start with in your scope angular will 2 way bind to the input, so any values that are initially set in the scope object will show up in the input
joshperry33.1k1313 gold badges7878 silver badges9595 bronze badges
charlietflcharlietfl![Serialize Form Data In Angularjs Serialize Form Data In Angularjs](/uploads/1/2/6/2/126217255/744909329.png)
Serialize Form Data
147k1313 gold badges9898 silver badges129129 bronze badges
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.