HomeEducationAjax with MVC - Passing HTML information as a listing of objects...

Ajax with MVC – Passing HTML information as a listing of objects Receive US

Take into account the next situation:

We have to move checklist of Merchandise and a statusId to the controller motion UpdateProducts.


        public class Product
            public int Id  get; set; 
<span class="redactor-invisible-space">            public int StatusId  get; set; 
            public string Identify  get; set; 


        public async Process<ActionResult> UpdateProducts(Record<Product> merchandise, int statusId)
            //Your logic right here utilizing Merchandise and statusId 
            return Json(new  @success = true );

To attain this we have to construct the Merchandise object after which stringify it into one object for the info to be handed as anticipated.


        var merchandise = $('#productTable enter[type="text"]').map(operate ()
            var obj = new Object();
            obj.Id = $(this).information("id");
            obj.Identify = $(this).val();
            obj.Standing = 1;
            return JSON.stringify(obj); //stringify particular person Product 
            contentType: 'software/json; charset=utf-8',
            dataType: 'json',
            url: '@Url.Motion("UpdateProducts")',
                kind: 'publish',
                information: JSON.stringify( merchandise: merchandise, statusId: 1) //stringify the entire information once more
            .completed(operate (consequence)
                 //consequence right here

For it to work, JSON.stringify must be utilized to every object, and once more to the entire output as proven within the above instance.

This characteristic allows you to move advanced information to a MVC controller.

#Ajax #MVC #Passing #HTML #information #checklist #objects

Continue to the category


Please enter your comment!
Please enter your name here

- Advertisment -spot_img

Most Popular

Recent Comments