ASP.NET Razor Engine SoftUni Team ASP.NET MVC Introduction

Slides:



Advertisements
Similar presentations
AngularJS Directives Defining Custom Directives SoftUni Team Technical Trainers Software University
Advertisements

ASP.NET MVC Architecture Layouts, Filters, Sections, Helpers, Partial Views, Areas… SoftUni Team Technical Trainers Software University
Working with Data Model Binders, Display Templates, Editor Templates, Validation… SoftUni Team Technical Trainers Software University
Doctrine The PHP ORM SoftUni Team Technical Trainers Software University
Stacks and Queues Processing Sequences of Elements SoftUni Team Technical Trainers Software University
Version Control Systems
Helpers, Data Validation
Auto Mapping Objects SoftUni Team Database Applications
Services & Dependency Injection
C# MVC Frameworks – ASP.NET
ASP.NET Essentials SoftUni Team ASP.NET MVC Introduction
Web API - Introduction AJAX, Spring Data REST SoftUni Team Web API
Introduction to MVC SoftUni Team Introduction to MVC
Deploying Web Application
PHP MVC Frameworks Course Introduction SoftUni Team Technical Trainers
PHP Fundamentals Course Introduction SoftUni Team Technical Trainers
Reflection SoftUni Team Technical Trainers Java OOP Advanced
Classes, Properties, Constructors, Objects, Namespaces
Mocking tools for easier unit testing
Parsing JSON JSON.NET, LINQ-to-JSON
State Management Cookies, Sessions SoftUni Team State Management
EF Code First (Advanced)
PHP MVC Frameworks MVC Fundamentals SoftUni Team Technical Trainers
Spring Filters Spring Interceptors SoftUni Team Spring Interceptors
Software Technologies
EF Relations Object Composition
Entity Framework: Code First
Unit Testing with Mocha
C#/Java Web Development Basics
MVC Architecture. Routing
Install and configure theme
Balancing Binary Search Trees, Rotations
Debugging and Troubleshooting Code
Entity Framework: Relations
Functional Programming
The Right Way Control Flow
ASP.NET Razor Engine SoftUni Team ASP.NET MVC Introduction
MVC Architecture, Symfony Framework for PHP Web Apps
Regular Expressions (RegEx)
MIS Professor Sandvig MIS 324 Professor Sandvig
ASP.NET MVC Introduction
Databases Advanced Course Introduction SoftUni Team Databases Advanced
C# Web Development Basics
Best practices and architecture
Design & Module Development
Magento Basics part 2 Modules & Themes Stenik Group Ltd. Magento
Built-in Functions. Usage of Wildcards
Multidimensional Arrays, Sets, Dictionaries
Extending functionality using Collections
ASP.NET REST Services SoftUni Team ASP.NET REST Services
Exporting and Importing Data
ASP.NET Filters SoftUni Team ASP.NET MVC Introduction
Making big SPA applications
Functional Programming
Exporting and Importing Data
Introduction to TypeScript & Angular
CSS Transitions and Animations
Train the Trainers Course
Iterators and Comparators
Spring Data Advanced Querying
Software Quality Assurance
Directives & Forms Capturing User Input SoftUni Team
Version Control Systems
JavaScript Frameworks & AngularJS
Polymorphism, Interfaces, Abstract Classes
Text Processing and Regex API
/^Hel{2}o\s*World\n$/
JavaScript: ExpressJS Overview
CSS Transitions and Animations
Iterators and Generators
Presentation transcript:

ASP.NET Razor Engine SoftUni Team ASP.NET MVC Introduction Technical Trainers Software University http://softuni.bg

Have a Question? sli.do #CSharpWeb

Table of Contents Razor HTML helpers Model validations

Advanced Razor Syntax

View Helpers Each view inherits WebViewPage ViewPage has a property named Html Html property has methods that return string and can be used to generate HTML Create inputs Create links Create forms Other helper properties are also available Ajax, Url, custom helpers

Common HTML Helpers HTML Helper Description @HTML.ActionLink Returns and anchor link @using (Html.BeginForm) { form content } Creates and html form @HTML.CheckBoxFor Creates a checkbox for a given property of the model @HTML.Display\For Displays the name of a given property @HTML.Editor\For Creates and editor\for a given property @HTML.Label\For Creates a label\for the given property

Other HTML Form Helpers HTML Helper @Html.DropDownList\For @Html.TextBox\For @Html.TextArea\For @Html.Password\For @Html.Hidden\For @Html.CheckBox\For @Html.RadioButton\For @Html.ListBox\For

Custom Helpers Write extension methods for the HtmlHelper Return a string or override the ToString() method The TagBuilder class manages closing tags and attributes Add namespace in web.config (if needed)

* Data Validation (c) 2008 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Validation with Annotations Attributes are defined in System.ComponentModel.DataAnnotations Covers common validation patterns Required StringLength Regex Range

Data Validation Attributes Description Required Checks whether a non-null value is assigned to the property. It can be configured to fail if an empty string is assigned. StringLength Checks whether the string is longer than the specified value. Compare Checks whether two specified properties in the model have the same value. Range Checks whether the value falls in the specified range. It defaults to numbers, but it can be configured to consider a range of dates, too. RegularExpression Checks whether the value matches the specified expression. CustomValidation Checks the value against the specified custom function. © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

Custom Validation Custom attributes Inherit ValidationAttribute

Validating Model – Controller ModelState.IsValid will give us information about the data validation success ModelState.AddModelError() will produce a custom error

Validating Model – View @Html.ValidationSummary() – output errors @Html.ValidationMessageFor(…) – outputs validation message for specified property Text box with integrated client-side validation jQuery validation library required for unobtrusive JavaScript validation P.S. Check Web.config

Class-Level Model Validation Your model should implemented IValidatableObject From now on, MVC (works with EF too) will validate the object by your custom rules

* Other Annotations (c) 2008 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Display / Edit Annotations Attribute Description DisplayName Friendly name for labels DisplayFormat Format strings and null display text DisplayColumn Specify the property of a model class for simple text display. HiddenInput Render value in a hidden input (when editing). Bind Tells the model binder which properties to include/exclude

ASP.NET Razor Engine https://softuni.bg/courses/ © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

License This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" license © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

Free Trainings @ Software University Software University Foundation – softuni.org Software University – High-Quality Education, Profession and Job for Software Developers softuni.bg Software University @ Facebook facebook.com/SoftwareUniversity Software University @ YouTube youtube.com/SoftwareUniversity Software University Forums – forum.softuni.bg © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.