Contents
How to use business logic in MVC Stack Overflow?
The user clicks the “delete” button next to one of the emails, the controller notifies the model to delete entry N, then notifies the view the model has changed. Perhaps the admin’s email should never be removed from the list. That’s a business rule, that knowledge belongs in the model.
Can a controller be used to validate a model?
Make sure you controller is only used to route information to the business logic layer. The controller should NOT have business logic directly in it. Any validation needs to be handled by IValidatable on the Model.
Is it possible to use MVC without data access logic?
It is entirely possible to design an application following an MVC approach without separating business logic and data access logic from the presentation layer and thus end up with a single tier design.
Where to put business logic in a model?
Make sure you controller is only used to route information to the business logic layer. The controller should NOT have business logic directly in it. Any validation needs to be handled by IValidatable on the Model. Any business logic needs to be routed to a separate layer.
How does the model represent the business rule?
The view may ultimately represent this rule somehow — perhaps the model exposes an “IsDeletable” property which is a function of the business rule, so that the delete button in the view is disabled for certain entries – but the rule itself isn’t contained in the view. The model is ultimately gatekeeper for your data.
When to use MVC for non trivial applications?
MVC is an architectural style for the presentation layer of an application. For non trivial applications, business logic/business rules/data access should not be placed directly into Models, Views, or Controllers.
How to create a business rule in.net?
First, let’s create a .NET class called Person with three public properties that will be used as rule fields, and two public void methods that we can use as rule actions. We’ll use this class as a source object for our rules.