다음은 내 아키텍처의 응용 프로그램입니다. 나는 MVC가 옳았는지 아닌지를 혼동 하는가? 나의 건축은 옳은가? 아니다.MVC - 모델 -보기 및 컨트롤러의 역할
보기 - 그것은 제출에, 그것은
컨트롤러 컨트롤러 호출하는 양식을 HTML 부분을 가지고, 사용자와 상호 작용 - 정보 추가가 유효한지 여부 것이 확인? (데이터베이스 포인트가 아니라 모든 필수 필드가 채워지는 날씨를 확인합니다.) 어떤 모델을 호출할지 결정합니다.
모델 -보기 클래스를 포함합니다. 또한 데이터베이스 처리를 위해 추가, 수정 또는 삭제와 같은 몇 가지 메소드가 있습니다.
이 오류가 올까요? 아니면 실수가 있습니까? 다음 내 코드의 샘플입니다
컨트롤러 :
public ActionResult AddCustomer(CustomerModel model) { if (ModelState.IsValid) { model.AddCustomer(); return RedirectToAction("Index", "Home"); } return (View("AddCustomer",model)); }Model:
public class AddBookModel { [Required(ErrorMessage = "The ISBN is required.")] [DisplayName("ISBN")] public String ISBN { get; set; }
[DisplayName("Title")] [Required(ErrorMessage = "The Title is required.")] public String Title { get; set; } [Required(ErrorMessage = "The Publisher is required.")] [DisplayName("Publisher")] public String Publisher { get; set; } public void AddBook() { using (BBBDataContext DCBook = new BBBDataContext()) { Book tableBook = new Book() { ISBN = this.ISBN, Title = this.Title, Publisher = this.Publisher, } DCBook.Books.InsertOnSubmit(tableBook); DCBook.SubmitChanges(); } }
보기 :
<% using (Html.BeginForm()) {%> <%= Html.ValidationSummary(true) %> <fieldset> <legend>Insert Book Record</legend> <table id="displayform" cellspacing="0" cellpadding="5"> <colgroup> <col span="1" style="text-align:right" /> <col span="2" style="text-align:left" /> </colgroup> <tr> <td class="editor-label"> <%= Html.LabelFor(model => model.ISBN) %> </td> <td class="editor-field"> <%= Html.TextBoxFor(model => model.ISBN) %> <%= Html.ValidationMessageFor(model => model.ISBN) %> </td> </tr> <tr> <td class="editor-label"> <%= Html.LabelFor(model => model.Title) %> </td> <td class="editor-field"> <%= Html.TextBoxFor(model => model.Title) %> <%= Html.ValidationMessageFor(model => model.Title) %> </td> </tr>