Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi friends ........
i am new in mvc2.I am using a dropdown list binds with table. empid,empname

there is textbox .i want to display age of selected employee in the textbox.how it is possible with j query.


any help solve my problem.
thanks..
Posted
Updated 22-Dec-11 1:31am
v3

1 solution

You can bind the change event of your drop down list using a bit of jQuery like so...

JavaScript
var url = '@Url.Action("GetEmployeeData", "YourController")';
$("#YourElementId").change(function () {
    $.post(url, { employeeId: $(this).val() }, function (data) {
        if (data.length > 0)
            // Do something with the results , populate your textbox
    });
});


Whenever your list changes index, it will attempt to make an ajax .post to a controller method called GetEmployeeData.

You could then write a controller method like so...

C#
public ActionResult GetEmployeeData(int employeeId)
{
    var employee = SomeObject.GetEmployee(employeeId);
    return Json(employee);
}


In the callback of the jquery script, read the JSON object and populate your text box
 
Share this answer
 
v2
Comments
Randeep Chauhan 22-Dec-11 7:48am    
thanks sir for your replay .i will check it.

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