Two code sections below: the first one is the drop down, which is how it needs to be. The second code section is the old code, which has the validation functionality. Can someone tell me where the validation stuff needs to go in the first code section?
<li class="country">
<label for="country" >Country:</label>
<select name="CountryId" id="CountryId">
<option value="">Select</option>
@foreach (var st in countries)
{
<option value="@st.CountryId">@st.CountryId</option>
}
</select>
</li>
<li class="country">
<label for="country" @if(!ModelState.IsValidField("country")){<text>class="error-label"</text>}>Country</label>
<input type="text" id="country" name="country" value="@country" @Validation.For("country") />
@* Write any country validation errors to the page *@
@Html.ValidationMessage("country")
</li>
wavemaster
Participant
1293 Points
1129 Posts
Validating an input of dropdown entry
Feb 14, 2013 01:29 AM|LINK
I am user proofing my forms.
Two code sections below: the first one is the drop down, which is how it needs to be. The second code section is the old code, which has the validation functionality. Can someone tell me where the validation stuff needs to go in the first code section?
<li class="country"> <label for="country" >Country:</label> <select name="CountryId" id="CountryId"> <option value="">Select</option> @foreach (var st in countries) { <option value="@st.CountryId">@st.CountryId</option> } </select> </li> <li class="country"> <label for="country" @if(!ModelState.IsValidField("country")){<text>class="error-label"</text>}>Country</label> <input type="text" id="country" name="country" value="@country" @Validation.For("country") /> @* Write any country validation errors to the page *@ @Html.ValidationMessage("country") </li>css-chlukito
Member
378 Points
49 Posts
Re: Validating an input of dropdown entry
Feb 21, 2013 01:16 AM|LINK
Hi,
I think can do like this
<li class="country"> <label for="country" @if(!ModelState.IsValidField("country")){<text>class="error-label"</text>}>Country:</label> <select name="country" id="country" @Validation.For("country") > <option value="">Select</option> @foreach (var st in countries) { <option value="@st.CountryId">@st.CountryId</option> } </select> @Html.ValidationMessage("country") </li>Please 'Mark as Answer' if this post helps you.