2016-12-12 5 views
1

내 코스에 코스, 제공 강좌, 코스 등록 테이블, 섹션 테이블이 있습니다. 각 사용자의 강좌 등록 시스템을 구현하고 싶습니다. enter image description here 이것은 프로젝트의 데이터베이스 다이어그램입니다. enter image description here 이와 같은 기능을 구현하고 싶습니다. 나는asp.net mvc를 사용하여 라디오 버튼 그룹을 구현하는 방법

class time . public class Course 
{ 
    [Key] 

    public int CourseId { get; set; } 
    [Required] 
    public string Name { get; set; } 
    public string Code { get; set; } 
    public string Credit { get; set; } 
    public DateTime RegDate { get; set; } 

    public string PreCourse { get; set; } 
    public int DepartmentId { get; set; } 
    [ForeignKey("DepartmentId")] 
    public virtual Department Department { get; set; } 
    public virtual ICollection<OfferedCourse> OfferedCourses { get; set; } 

} 

이 내 코스 모델의 기능,

public class Department 
    { 
    [Key] 
    public int DepartmentId { get; set; } 
    [Required] 
    public string Name { get; set; } 
    [Required] 
    public string Code { get; set; } 
    public virtual ICollection<ApplicationUser> ApplicationUsers { get; set; } 
    public virtual ICollection<Course> Courses { get; set; } 
} 

를 구현하지 않는이 내 부서 모델,

 public class OfferedCourse 
{ 
    [Key] 
    public int OfferedCourseId { get; set; } 
    public int Capacity { get; set; } 
    public bool Status { get; set; } 
    public int CourseId { get; set; } 
    [ForeignKey("CourseId")] 
    public virtual Course Course { get; set; } 
    public string TeacherId { get; set; } 
    [ForeignKey("TeacherId")] 
    public virtual ApplicationUser ApplicationUser { get; set; } 
    public int SectionId { get; set; } 
    [ForeignKey("SectionId")] 
    public virtual Section Section { get; set; } 
    public int SemesterId { get; set; } 
    [ForeignKey("SemesterId")] 
    public virtual Semester Semester { get; set; } 
    public virtual ICollection<CourseRegistration> CourseRegistrations { get; set; } 

} 

이 각 학기 내 제공되는 과정입니다.

 public class Section 
{ 
    [Key] 
    public int SectionId { get; set; } 

    public string Title { get; set; } 



} 

이것은 내 섹션 모델입니다.이 프로젝트에서 교사, 학생 같은 사용자를 관리하기 위해 asp.net ID 프레임 워크를 사용하고 있습니다. 그러나 수강 신청보기에서 라디오 버튼을 관리하는 여러 방법을 시도했습니다. 내가 섹션 물론 이름과 같은 데이터의 다른 유형을 가지고 있기 때문에 내가 어떻게이

+0

이미지는 라디오 버튼이 아닌 체크 상자를 보여줍니다. 모델에서 제안한대로 여러 코스를 선택하려고한다고 가정하면 [이 답변] (http://stackoverflow.com/questions/29542107/pass-list-of-checkboxes-into-view-and-pull-out- ienumerable/29554416 # 29554416)보기 모델 및보기의 일반적인 예를 보려면 –

+0

예. 라디오 버튼이 필요합니다 .. 어떻게하면됩니까 .... 뷰 모델이 필요합니다.하지만 어떻게 구현할 수 있습니까? –

+0

죄송합니다. 불가능합니다. 당신이 보여준 것을 이해하십시오. "과학 학사 ...."당신의'Section.Title' 속성입니까? 그 아래에있는 3 개의 아이템은 그 섹션을위한'OfferedCourses'입니까? 당신은 그 중 3 개 중 하나만 선택하고 싶습니까? –

답변

-1

내가 라디오 버튼 그룹을 사용하기 위해 쉽게 생각 처리 할 수있는이 기능을 구현 수있는 방법 ... 이 링크 http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_radio

하지만에 대한 참조

<script> 
$('#register-btn').click(function() { 
    var regType = 0; 
    if ($('#radio1').is(":checked")) { 
     regType = 1; 
    } 
    if ($('#radio2').is(":checked")) { 
     regType = 2; 
    } 
    if ($('#radio3').is(":checked")) { 
     regType = 3; 
    } 
    $.ajax({ 
     type: "POST", 
     url: "/Registration/reg_Ajax", 
     contentType: "application/json; charset=utf-8", 
     data: '{type: "' + regType + '"}', 
     dataType: "text", 
     success: function (response) { 
      alert(response); 
     }, 
     failure: function (response) { 
      alert("fail"); 
     }, 
     error: function (request, status, error) { 
      alert('error'); 
     } 
    }); 
}); 

보기 :

등록 페이지는 귀하의 요청을 처리하기 위해 자바 스크립트 if else 코드를 사용한다

<form> <input type="radio" name="reg" value="male" id="radio1" checked> Male<br> <input type="radio" name="reg" value="female" id="radio2"> Female<br> <input type="radio" name="reg" value="other" id="radio3"> Other <br> <input type="Button" value="Register" id="register-btn"> </form>

+0

처음에는 어떻게 처리 할 수 ​​있을까? –

0

mvc 면도기를 사용하는 경우 foreach를 사용하여 RadioButton을 생성 할 수 있습니다. 다음과 같이 입력하십시오 :

//HTML code here 
@foreach (var offeredCourse in Model.OfferedCourses) 
{  
    @Html.RadioButton(offeredCourse.OfferedCourseId.ToString(), offeredCourse.ID)   
} 
//HTML code here 

하지만 사용중인 모델이 확실하지 않습니다. 귀하의 코스 등록보기 코드를 붙이십시오.이 답변과 더욱 관련이 있습니다.

+0

섹션은 다른 테이블 –

+0

각 주제는 많은 섹션을 가지고 있습니다 ... 개별 주제별 섹션별로 라디오 버튼을 생성해야합니다. –

+0

내가해야할 일을 이해하지 못하기 때문에 어떤 코스 등록보기 모델도 작성하지 않았습니다. 그러나 코스 등록보기 모델은 제공된 코스 아이디를 사용하여 섹션을 찾을 수 있기 때문에 이러한 속성 studentId를 제공합니다. –