|
1 | | -@using System.ComponentModel.DataAnnotations; |
| 1 | +@using System.ComponentModel.DataAnnotations; |
2 | 2 |
|
3 | 3 | <h2>Customer Registration Form</h2> |
4 | 4 |
|
5 | | -<EditForm Model="@CustomerDetails" OnValidSubmit="@HandleValidSubmit"> |
| 5 | +<EditForm Model="@_customerDetails" OnValidSubmit="@HandleValidSubmit"> |
6 | 6 | <DataAnnotationsValidator /> |
7 | 7 | <div class="row"> |
8 | 8 | <div class="col-md-6"> |
9 | 9 | <label class="form-label">First Name :</label> |
10 | | - <SfTextBox @bind-Value="@CustomerDetails.FirstName"></SfTextBox> |
11 | | - <ValidationMessage For="@(() => CustomerDetails.FirstName)"></ValidationMessage> |
| 10 | + <SfTextBox @bind-Value="@_customerDetails.FirstName"></SfTextBox> |
| 11 | + <ValidationMessage For="@(() => _customerDetails.FirstName)"></ValidationMessage> |
12 | 12 | </div> |
13 | 13 | <div class="col-md-6"> |
14 | 14 | <label class="form-label">Last Name :</label> |
15 | | - <SfTextBox @bind-Value="@CustomerDetails.LastName"></SfTextBox> |
16 | | - <ValidationMessage For="@(() => CustomerDetails.LastName)"></ValidationMessage> |
| 15 | + <SfTextBox @bind-Value="@_customerDetails.LastName"></SfTextBox> |
| 16 | + <ValidationMessage For="@(() => _customerDetails.LastName)"></ValidationMessage> |
17 | 17 | </div> |
18 | 18 | </div> |
19 | 19 | <div class="row"> |
20 | 20 | <div class="col-md-6"> |
21 | 21 | <label class="form-label">Gender :</label> |
22 | | - <SfComboBox TValue="string" TItem="Gender" @bind-Value="@CustomerDetails.Gender" DataSource="@Genders"> |
| 22 | + <SfComboBox TValue="string" TItem="Gender" @bind-Value="@_customerDetails.Gender" DataSource="@_genders"> |
23 | 23 | <ComboBoxFieldSettings Text="Name" Value="Code"></ComboBoxFieldSettings> |
24 | 24 | </SfComboBox> |
25 | | - <ValidationMessage For="@(() => CustomerDetails.Gender)"></ValidationMessage> |
| 25 | + <ValidationMessage For="@(() => _customerDetails.Gender)"></ValidationMessage> |
26 | 26 | </div> |
27 | 27 | <div class="col-md-6"> |
28 | 28 | <label class="form-label">Date of Birth :</label> |
29 | | - <SfDatePicker @bind-Value="@CustomerDetails.DateOfBirth"></SfDatePicker> |
30 | | - <ValidationMessage For="@(() => CustomerDetails.DateOfBirth)"></ValidationMessage> |
| 29 | + <SfDatePicker @bind-Value="@_customerDetails.DateOfBirth"></SfDatePicker> |
| 30 | + <ValidationMessage For="@(() => _customerDetails.DateOfBirth)"></ValidationMessage> |
31 | 31 | </div> |
32 | 32 | </div> |
33 | 33 | <div class="row"> |
34 | 34 | <div class="col-md-9"> |
35 | 35 | <label class="form-label">Email ID :</label> |
36 | | - <SfTextBox @bind-Value="@CustomerDetails.Email"></SfTextBox> |
37 | | - <ValidationMessage For="@(() => CustomerDetails.Email)"></ValidationMessage> |
| 36 | + <SfTextBox @bind-Value="@_customerDetails.Email"></SfTextBox> |
| 37 | + <ValidationMessage For="@(() => _customerDetails.Email)"></ValidationMessage> |
38 | 38 | </div> |
39 | 39 | <div class="col-md-3"> |
40 | 40 | <label class="form-label">Phone Number :</label> |
41 | | - <SfTextBox @bind-Value="@CustomerDetails.PhoneNumber"></SfTextBox> |
42 | | - <ValidationMessage For="@(() => CustomerDetails.PhoneNumber)"></ValidationMessage> |
| 41 | + <SfTextBox @bind-Value="@_customerDetails.PhoneNumber"></SfTextBox> |
| 42 | + <ValidationMessage For="@(() => _customerDetails.PhoneNumber)"></ValidationMessage> |
43 | 43 | </div> |
44 | 44 | </div> |
45 | 45 | <div class="row"> |
46 | 46 | <div class="col-md-12"> |
47 | 47 | <label class="form-label">Address :</label> |
48 | | - <SfTextBox Multiline=true @bind-Value="@CustomerDetails.Address"></SfTextBox> |
49 | | - <ValidationMessage For="@(() => CustomerDetails.Address)"></ValidationMessage> |
| 48 | + <SfTextBox Multiline=true @bind-Value="@_customerDetails.Address"></SfTextBox> |
| 49 | + <ValidationMessage For="@(() => _customerDetails.Address)"></ValidationMessage> |
50 | 50 | </div> |
51 | 51 | </div> |
52 | 52 | <div class="row"> |
53 | 53 | <div class="col-md-6"> |
54 | 54 | <label class="form-label">Password :</label> |
55 | | - <SfTextBox @bind-Value="@CustomerDetails.Password"></SfTextBox> |
56 | | - <ValidationMessage For="@(() => CustomerDetails.Password)"></ValidationMessage> |
| 55 | + <SfTextBox @bind-Value="@_customerDetails.Password"></SfTextBox> |
| 56 | + <ValidationMessage For="@(() => _customerDetails.Password)"></ValidationMessage> |
57 | 57 | </div> |
58 | 58 | <div class="col-md-6"> |
59 | 59 | <label class="form-label">Confirm Password :</label> |
60 | | - <SfTextBox @bind-Value="@CustomerDetails.ConfirmPassword"></SfTextBox> |
61 | | - <ValidationMessage For="@(() => CustomerDetails.ConfirmPassword)"></ValidationMessage> |
| 60 | + <SfTextBox @bind-Value="@_customerDetails.ConfirmPassword"></SfTextBox> |
| 61 | + <ValidationMessage For="@(() => _customerDetails.ConfirmPassword)"></ValidationMessage> |
62 | 62 | </div> |
63 | 63 | </div> |
64 | 64 | <div class="row"> |
|
69 | 69 | </EditForm> |
70 | 70 |
|
71 | 71 | @code { |
72 | | - private Customer CustomerDetails; |
73 | | - private List<Gender> Genders; |
| 72 | + private Customer _customerDetails; |
| 73 | + private List<Gender> _genders; |
74 | 74 |
|
75 | 75 | // Handle form submission |
76 | 76 | private void HandleValidSubmit() |
|
80 | 80 |
|
81 | 81 | protected override void OnInitialized() |
82 | 82 | { |
83 | | - CustomerDetails = new Customer(); |
84 | | - Genders = new Gender().GetGender(); |
| 83 | + _customerDetails = new Customer(); |
| 84 | + _genders = new Gender().GetGender(); |
85 | 85 | } |
86 | 86 |
|
87 | 87 | // Data model class |
|
108 | 108 | [Required(ErrorMessage = "Gender is required")] |
109 | 109 | public string Gender { get; set; } |
110 | 110 |
|
111 | | - [Required(ErrorMessage = "PhoneNumber is required")] |
| 111 | + [Required(ErrorMessage = "Phone number is required")] |
112 | 112 | [DataType(DataType.PhoneNumber)] |
113 | 113 | [Phone] |
114 | 114 | public string PhoneNumber { get; set; } |
|
126 | 126 | public string ConfirmPassword { get; set; } |
127 | 127 | } |
128 | 128 |
|
129 | | - // Combobx options class |
| 129 | + // Combobox options class |
130 | 130 | public class Gender |
131 | 131 | { |
132 | 132 | // Properties for gender options |
|
136 | 136 | // Method for gender options |
137 | 137 | public List<Gender> GetGender() |
138 | 138 | { |
139 | | - List<Gender> Gender = new List<Gender> |
| 139 | + List<Gender> genders = new List<Gender> |
140 | 140 | { |
141 | 141 | new Gender() { Name = "Male", Code = "M" }, |
142 | 142 | new Gender() { Name = "Female", Code = "F" }, |
143 | 143 | new Gender() { Name = "Other", Code = "O" }, |
144 | 144 | }; |
145 | | - return Gender; |
| 145 | + return genders; |
146 | 146 | } |
147 | 147 | } |
148 | 148 | } |
0 commit comments