由Json将数据发送到asp.net mvc 5中的控制器 [英] Sending data by Json into controller in asp.net mvc 5
问题描述
您好b $ b
我有3个班级作为学生,课程和学生课程。
班级学生有以下字段:
Id ,姓名,家庭
课程有以下字段:
Id,CourseName
班级学生课程有以下字段:
Id,StudentId,CourseId
在我的页面中,我想从下拉列表中选择一个学生名称来自其他Dropdown .user的课程名称可以添加几个课程,每次新记录出现在我的表中同一页面而不刷新,然后当用户点击提交时,表中的所有记录必须存储在类StudentCourses中。我想用Json做这个但我不知道怎么写它的代码。有人有样品吗?
谢谢
Hi
I have 3 classes as Student ,Course and StudentCourses .
Class Student has below fields:
Id,Name,Family
Class course has below fields:
Id,CourseName
Class StudentCourses has below fields:
Id,StudentId,CourseId
In my page I want to choose a StudentNames from dropdown and course names from other Dropdown .user could add several course and each time the new record appear in my table in same page without refresh ,then when user click on submit all the records in table must store in class StudentCourses .I want do this with Json but I dont know how to write it's codes .Anybody has sample ?
Thanks
推荐答案
为此请参阅以下代码
For that see the following code
Controllers ->
public JsonResult GetStudents(int id)
{
var states = db.Students.Where(x => x.courseID == id).ToList();
return Json(states, JsonRequestBehavior.AllowGet);
}
观看次数 - > Jquery
Views -> Jquery
(#ddlCourse)。change(function(){
var url =/ Controls_ / GetStudents;
var courseID =
("#ddlCourse").change(function () { var url = "/Controls_/GetStudents"; var courseID =
(#ddlCourse)。val();
("#ddlCourse").val();
这篇关于由Json将数据发送到asp.net mvc 5中的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!