Create CSHTML
Create CSHTML
cshtml
Html Code
1- Html Tag Helper
• Hyperlink
• <a href="/Speaker/Detail/12">SpeakerId: 12</a>
• <a asp-controller="Speaker" asp-action="Detail" asp-route-id=“12">SpeakerId: 12</a>
• Input
• <input asp-for=“property" class="form-control" />
• Text : Property is String
• Number : Property is numeric
• Date : Data type of property is Date
• Time : : Data type of property is Time
• Password: Data type of property is password
• Checked : property is boolean
1- Html Tag Helper
• <input type="radio" asp-for="Property" value="Male" Checked /> Male
• <input type="Checkbox" asp-for="Property" value="1" Checked /> Active
• Select
• Controller (HttpGet Create() )
• ViewBag.country = new List<string> { "Jordan" , "Syria" , "Palestine" };
• Html
• <select asp-for="Country" class="form-select" asp-items="new
SelectList(ViewBag.country)" ></select>
2- Model Validation
• Data Type
• [DataType(DataType.EmailAddress)]
• [DataType(DataType.Date)]
• [DataType(DataType.Password)]
• Etc
• Required
• [Required(ErrorMessage =“Message")]
• Range
• [Range(min, max, ErrorMessage =“Message")]
2- Model Validation
• StringLength
• [StringLength(max)]
• [StringLength(max,MinimumLength =min,ErrorMessage ="")]
• Compare
• [Compare(“Property",ErrorMessage ="")]
Programming Create (HTML)
• Form
• <form enctype="multipart/form-data" asp-action="New">
• Control
• <div class="custom-file">
<input asp-for="ProfileImage" class="custom-file-input" id="customFile">
<label class="custom-file-label" for="customFile">Choose file</label>
</div>