Documentation
SolutionDeveloperComplianceProjects
  • Getting Started
  • Technology
    • Application Framework
    • Object-Relational Mapping
    • Security Framework
    • Architecture Pattern
    • API Management
  • Environment
    • Development Tool
    • Database Server
    • Web Server
  • PRESENTATION
    • Design Material
    • HTML Helpers
    • Icon Images
    • Custom CSS
    • JQuery Plugin
      • DataTables
      • Tabs
      • Date Picker
      • Calendar
      • Chart
      • Treeview
    • Client Script
      • Open Modal
      • Close Modal
      • Handle return data
      • Load Content
      • Change Hash
      • Change Title
      • Get actual Hash
      • Get Content
      • Update Content
      • Delete Content
      • Get Partial Content
      • Get Partial Content Async
      • Update Partial Content
      • Update Partial Content Async
      • Delete Partial Content
      • Get Action
      • Update Action
      • Delete Action
      • Cascading Dropdown
      • Display Document
    • MVC View
  • BACKEND
    • Base Controller
    • Controller
    • Base Model
    • View Model
    • Class Utility
      • Constant Values
      • Global Properties
      • Option Helper
      • Setting Helper
    • Data Repository
      • Read Columns
      • Read All Columns
      • Read First Record
      • Read by Primary Key
      • Find Record
      • Insert Record
      • Update Record
      • Delete Entity
      • Delete by Criteria
      • Delete by Primary Key
      • Counting Record
      • Check Exist
      • Generate Row-Id
    • Unit Of Work
    • Data Entity
  • Application Features
    • Account Management
    • Navigation Editor
    • Access Control
  • Examples
    • Simple Page
    • Master Detail
    • Editor Template
Powered by GitBook
On this page
  • General information
  • Examples
  • Example 1: Text Box
  • Example 2: Text Area
  • Example 3: Check Box
  • Example 4: Dropdown List
  • Example 5: Hidden
  • Attributes
  1. PRESENTATION

HTML Helpers

General information

HTML Helpers are methods in ASP.NET MVC that are used to generate HTML elements in a View. They are used to create and render HTML controls (such as textboxes, dropdownlists, checkboxes, etc.) in a strongly-typed and efficient way. They provide a way to create reusable and consistent HTML code, reducing the amount of repetitive and error-prone markup that needs to be written. HTML Helpers take model properties as input and generate the appropriate HTML, which means that HTML Helpers also play a role in model binding and validation.

Examples

Example 1: Text Box

The following code will generate a text input field with the value of the "Name" property of the Model:

@Html.TextBoxFor(mdl => mdl.Name)

Example 2: Text Area

The following code will generate a text area tied to the "Description" property of the Model:

@Html.TextAreaFor(mdl => mdl.Description)

Example 3: Check Box

The following code will generate a check box for the boolean property "IsOn" of the Model:

@Html.CheckBoxFor(mdl => mdl.IsOn)

Example 4: Dropdown List

The following code will generate a dropdown list taking the items from the list "PersonList" of the Model:

@Html.DropDownListFor(mdl => mdl.Person, @Converter.ToMvcList(Model.PersonList))

It is necessary to convert the List in the Model to a form that can be put in a dropdown list, which is why the second argument was included in this HTML Helper function.

Example 5: Hidden

The following code will generate an invisible element storing the value of the ID Property of the Model:

@Html.HiddenFor(mdl => mdl.ID)

Attributes

HTML Helpers can also have attributes like HTML Tags, such as "id", "class", "style" and "readonly". They are specified the following way:

@Html.TextBoxFor(mdl => mdl.Name, new { @id = "someId", @class = "someClass", @style = "width:90%", @readonly = readonly })
PreviousDesign MaterialNextIcon Images

Last updated 2 years ago