I just wonder when we pass data to controller method as parameters, why we need to use exactly the same name, any underlying reason?
For example, the following ajax call:
$.ajax({
// Get Faculty PartialView
url: "/Home/FacultiesToPVDemo",
type: 'Get',
data: { courseName: selectedCourseName },
success: function (data) {
$("#facultyDetailTable").empty().append(data);
},
error: function () {
alert("something seems wrong");
}
});
will invoke the following method in the controller:
public ActionResult FacultiesToPVDemo(string courseName)
{
IEnumerable<Course> allCourses = _repository.GetCourses();
var selectedCourseId = (from c in allCourses where c.CourseName == courseName select c.CourseId).FirstOrDefault();
IEnumerable<Faculty> allFaculties = _repository.GetFaculties();
var facultiesForCourse = allFaculties.Where(f => f.AllotedCourses.Any(c => c.CourseId == selectedCourseId)).ToList();
return PartialView("FacultyPV", facultiesForCourse);
}
In the ajax if I use a different data property name other than "courseName", it wouldn't work, even if there is only one parameter to match. why is that?