以下は、アプリケーションの私のアーキテクチャです。MVC を正しく理解しているかどうかについて混乱していますか? 私のアーキテクチャは正しいですか?
ビュー - ユーザーと対話します。HTML 部分があり、コントローラーを呼び出すフォームを送信します
コントローラー - 追加された情報が有効かどうかをチェックしますか? (データベースの観点ではありません。すべての必須フィールドが入力されているかどうかを確認するだけですか?)どのモデルを呼び出すかを決定します。
モデル - ビューのクラスが含まれています。また、データベースを処理するための追加、変更、削除などのメソッドもあります。
これは正しいですか、それとも間違いですか?以下は私のコードのサンプルです
コントローラ:
public ActionResult AddCustomer(CustomerModel モデル)
{
if (ModelState.IsValid)
{
モデル.AddCustomer();
return RedirectToAction("インデックス", "ホーム");
}
return (View("AddCustomer",モデル));
}
モデル:
パブリック クラス AddBookModel
{
[必須(ErrorMessage = "ISBNが必要です。")]
[表示名("ISBN")]
public String ISBN { 取得; 設定; }
[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>