2016-11-03 2 views
0

프로젝트를 ASP.net Forms에서 ASP.Net MVC Core로 변환 중입니다.여러 행의 데이터 저장 및 게시 ASP.Net MVC

는 다음과 같은 형식을 고려 : 나는 새받는 사람을 만드는거야 enter image description here

을, 그리고받는 사람이 여러 연락처 방법이있을 수 있습니다. 다음 내 ASP.Net에서 enter image description here

내가 리피터를했다, 응용 프로그램을 형성하고, 난 그냥 중계기에 새로운 요소를 추가하고 양식 :

에서 다음 모달납니다 연락 방법 추가 버튼을

제출되었으므로 리피터 행을 반복하고 데이터베이스를 채 웁니다.

MVC에서 어떻게합니까? html 테이블을 만들고 그 행을 반복합니까?

저는 MVC를 처음 사용하기 때문에 여기에서 진행하는 방법을 모르겠습니다.

public class Recipient 
{ 
    [Key] 
    public Guid RecipientGUID { get; set; } 

    public string FirstName { get; set; } 

    public string LastName { get; set; } 

    public string Company { get; set; } 

    public UserGroup Owner { get; set; } 

    public List<ContactMethod> ContactMethods { get; set; } 

    public User CreatedBy { get; set; } 

    public DateTime CreatedOn { get; set; } 

    public User LastModifiedBy { get; set; } 

    public DateTime LastModifiedOn { get; set; } 

    public bool IsActive { get; set; } 

} 

연락 방법 :

public class ContactMethod 
{ 
    [Key] 
    [HiddenInput(DisplayValue = false)] 
    public Guid ContactMethodGUID { get; set; } 

    [Required(ErrorMessage = "Please specify a type.")] 
    public ContactMethodType Type { get; set; } 

    [Required] 
    public Recipient Recipient { get; set; } 

    public int CountryCode { get; set; } 

    [Required(ErrorMessage = "Please enter a identifier.")] 
    public string Identifier { get; set; } 

    public bool IsPreferred { get; set; } 
} 
+0

는 [이 답변]을 참조하시기 ASP.NET MVC 면도기 튜토리얼 (http://stackoverflow.com/questions/28019793/submit-same-partial-view-called-multiple-times를 봐 -data-to-controller/28081308 # 28081308) 컬렉션 항목을 동적으로 추가하는 옵션 –

답변

2

당신은 당신의 .cshtml보기 파일에 면도기 구문을 사용합니다 참고로

여기받는 사람과의 접촉 방법에 대한 내 데이터 모델이다.

<table> 
@foreach var recipient in model.Recipients 
{ 
    <tr><td>@recipient.FirstName</td></tr> 
} 
</table> 

+0

@ recipient.FirstName – James

+1

@Ya @가 필요하지 않은 @ {// code} 블록에 있기 때문에 생각했습니다. .. –

+0

고맙습니다.하지만 컬렉션에 새 행을 추가하는 방법은 무엇입니까? 면도칼로 할 수 있니? 또는 컨트롤러를 호출하고 데이터를 다시 게시해야합니까? 그래서받는 사람이 있으며 연락 방법 목록에 전화와 전자 메일을 추가하려고합니다. 그 부분은 저를 데려 오는 부분입니다. – MarekT

관련 문제