jQuery を使用して、ID を渡す非同期アクションを呼び出し、その結果を戻り値で埋めることができます。次のようなものを試してください。
$(document).ready(function() {
$("#employeeId").change(function() {
$.ajax({
url: '@Url.Action("GetEmployeeData", "Employee")',
type: 'POST',
dataType: 'json',
data: { employeeId : $("#employeeId").val() },
contentType: 'application/json; charset=utf-8',
success: function (data) {
if (data.success)
{
// fill the employee name
$("#employeeName").val(data.employeeName);
}
else
{
// show a message in a alert or div
alert('This Employee ID is not valid. Try again!');
$("#employeeId").text("").focus();
}
}
});
});
});
そして、あなたのアクションで、Josn メソッドの return に追加するだけで、名前または必要なプロパティを返す post メソッドを作成してみてください。
[HttpPost]
public ActionResult GetEmployeeData(string employeeId)
{
var employee = /* get your employee using employeeId parameter from Repository*/;
if (employee != null)
{
return Json(new { success = true, employeeName = employee.Name });
}
return Json(new { success = false });
}