MVC Project
Step 1: Model
right click on the model folder and create new class with name attend contains 5 public properties (id,email,gps,location,willAttend)
Step 2: Controller
Right click on controller folder and create new empty controller "StartController", which contains one default method "Index" that return "View" of type "IActionResult"
View take two parameters
1) View Name= RazorPageName
2) Data Objects to send data from controller to view
Notes:
IActionResult is an abstract class that can have several subtypes.
IActionResult Subtypes
- ViewResult - Renders a specifed view to the response stream
PartialViewResult - Renders a specifed partial view to the response stream
EmptyResult - An empty response is returned
RedirectResult - Performs an HTTP redirection to a specifed URL
RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data
JsonResult - Serializes a given ViewData object to JSON format
JavaScriptResult - Returns a piece of JavaScript code that can be executed on the client
ContentResult - Writes content to the response stream without requiring a view
FileContentResult - Returns a file to the client
FileStreamResult - Returns a file to the client, which is provided by a Stream
FilePathResult - Returns a file to the client
Step 3: View
Right click on the view folder and create new folder with name "start" contains razor page with name "StartView"
Notes:
- When send data from controller to view, use @model to define the type of information we send
- View can be a part of General Design template and we can set the required template using @{Layout = "_Layout";}
- the default template are defined on "_ViewStart.cshtml" page
- View can send data to main template using @{ ViewData["Title"] = "StartView"; }
- Main Layout contains @RenderBody() to set view output inside the main template
- Razor Pages can contains for loops and if statement like this
- Razor page can fill the object that you can read on controller like this
- You can setup the default CSS for invalid fields like this
<style>
.field-validation-error {color: #f00;}
.field-validation-valid { display: none;}
.input-validation-error { border: 1px solid #f00; background-color: #fee; }
.validation-summary-errors { font-weight: bold; color: #f00;}
.validation-summary-valid { display: none;}
</style>
No comments:
Post a Comment