Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please any one provide one sample for.


How to call the controller method on text change in mvc and also able to retrieve all data from view to controller


Thanks
Posted
Comments
[no name] 24-Oct-13 6:47am    
use ajax call on text change event

1 solution

You can use ajax call to do the task.
TextChanged event of your textBox write ajax call to your controller.
JavaScript
$(document).ready(function(){
   $("#YourTextBoxID").TextChanged(function(){
       $.ajax({
             Type:"GET/POST",
             ContentType:"application/json;charset=utf-8",
             url:'@Url.Action("ActionName","ControllerName")',
             data:{allData : Json.Stringify(Model)},
             dataType:"json",
             success: function(data){
                 alert(data.property1 + data.property2 + ...);
             },
             error: function(){
                 alert("Error");
             }             
 
       });
 
   });
});


You can return
C#
List<modelclassobjects>
or single model class object from Controller and access it by its property name.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900