I'd like to use AngularJS for databinding but I also want to keep a Send button that will submit the form sending the model (which the controller will change to a c sharp object) without ajax. I know I have the model in the $scope and that it is in json format, but it seems that the only way to send it to an Action is via Ajax and not by submitting the entire form.
1 Answer
When binding the data using AngularJS if you specify the name attribute, the action method in C# should receive the values.
For example, <input type='text' name='userName' value={{userName}} />
When user clicks the submit button, the server site method should receive the value if you have a variable named userName.
- Hello Shahed! I'm talking about an Object here. Like an object "Order" that has OrderItems. The name of the text field for an order item will be something like order_orderItem_0_product, order_orderItem_1_product. If I use angular, how can I specify the name to be like that?– Shak HamCommentedFeb 14, 2014 at 22:07
- Hi Shak, If you like to have the name in specific format, you could bind that too using Angular. For example, name='{{x.propertyName}}' value={{x.value}} Then, on server side these values can be accessed from the "FormCollection collection" parameter.– ShahedCommentedFeb 14, 2014 at 22:37