Tutorial by Examples: attribut

Caller info attributes can be used to pass down information about the invoker to the invoked method. The declaration looks like this: using System.Runtime.CompilerServices; public void LogException(Exception ex, [CallerMemberName]string callerMemberName = "", ...
Elements and attributes behave differently with respect to default namespaces. This is often the source of confusion. An attribute whose name has no prefix lives in no namespace, also when a default namespace is in scope. <?xml version="1.0"?> <foo attr="value" xmlns=...
Model using System.ComponentModel.DataAnnotations; public class ViewModel { [Required(ErrorMessage="Name is required")] public string Name { get; set; } [StringLength(14, MinimumLength = 14, ErrorMessage = "Invalid Phone Number")] [Required(ErrorMessag...
Attributes are name-value pairs associated with an element. They are represented by values in single or double quotes inside the opening element tag, or the empty element tag if it is an empty element. <document> <anElement foo="bar" abc='xyz'><!-- some content -->&l...
Along with classic way of route definition MVC WEB API 2 and then MVC 5 frameworks introduced Attribute routing: public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // This...
This validation restricts the insertion of only numeric values. class Player < ApplicationRecord validates :points, numericality: true validates :games_played, numericality: { only_integer: true } end Besides :only_integer, this helper also accepts the following options to add constrai...
This helper validates that the attribute's value is unique right before the object gets saved. class Account < ApplicationRecord validates :email, uniqueness: true end There is a :scope option that you can use to specify one or more attributes that are used to limit the uniqueness check: ...
This helper validates that the specified attributes are not empty. class Person < ApplicationRecord validates :name, presence: true end Person.create(name: "John").valid? # => true Person.create(name: nil).valid? # => false You can use the absence helper to validate th...
class Person < ApplicationRecord validates :name, length: { minimum: 2 } validates :bio, length: { maximum: 500 } validates :password, length: { in: 6..20 } validates :registration_number, length: { is: 6 } end The possible length constraint options are: :minimum - The attribut...
<div [class.active]="isActive"></div> <span [style.color]="'red'"></span> <p [attr.data-note]="'This is value for data-note attribute'">A lot of text here</p>
If you need to add an attribute through razor that has a - (hyphen) in the name you cannot simply do @Html.DropDownListFor(m => m.Id, Model.Values, new { @data-placeholder = "whatever" }) it will not compile. data-* attributes are valid and common in html5 for adding extra values t...
using System; using System.Web; using System.Web.Mvc; namespace Example.SDK.Filters { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] public sealed class CustomErrorHandlerFilter : HandleErrorAttribute { public override void OnExceptio...
The Required attribute specifies that a property is required. An error message can be specified on using the ErrorMessage property on the attribute. First add the namespace: using System.ComponentModel.DataAnnotations; And apply the attribute on a property. public class Product { [Require...
The StringLength attribute specifies the minimum and maximum length of characters that are allowed in a data field. This attribute can be applied on properties, public fields and parameters. The error message must be specified on the ErrorMessage property on the attribute. The properties MinimumLeng...
A list of recognised color keyword names can be found in the W3C Recommendation for SVG. <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <circle r="30" cx="100" cy="100" fill="red" stroke=&qu...
Rust's #[path] attribute can be used to specify the path to search for a particular module if it is not in the standard location. This is typically discouraged, however, because it makes the module hierarchy fragile and makes it easy to break the build by moving a file in a completely different dire...
Adding a Conditional attribute from System.Diagnostics namespace to a method is a clean way to control which methods are called in your builds and which are not. #define EXAMPLE_A using System.Diagnostics; class Program { static void Main() { ExampleA(); // This method will ...
<link rel="stylesheet" href="test.css" media="print"> Media specifies what style sheet should be used for what type of media. Using the print value would only display that style sheet for print pages. The value of this attribute can be any of the mediatype val...
<form asp-action="create" asp-controller="Home" asp-route-returnurl="dashboard" asp-route-from="google"> <!--Your form elements goes here--> </form> This will generate the below markup <form action=&qu...
Some attributes are directly accessible as properties of the element (e.g. alt, href, id, title and value). var a = document.querySelector("a"), url = a.href; Other attributes, including data-attributes can be accessed as follows: var a = document.querySelector("a"), ...

Page 2 of 10