Following is my Architecture of an application. I am confuse with whether I understood MVC correct or not? My Architecture is right or not?
View - interacts with the user, it has HTML part, on submit the form it calls controller
Controller - it checks for information added is valid or not? (not database point of view. it will just check for weather all the mandatory fields are filled or not?) decides which model to call.
Model - it contains class of view. and also some methods like add,modify or delete to deal with the database.
Is this correct or making some mistake? Following is sample of my code
Controller:
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(); } }
View:
<% 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>