I'm new to MVC3. I have problem in custom validation, for example
In my BasicInfoViewModel.cs,
[Required]
[Display(Name = "State", ResourceType = typeof(Resources.Global))]
public string State { get; set; }
[Display(Name = "City", ResourceType = typeof(Resources.Global))]
public string City { get; set; }
In my BasicDetailsView.cshtml,
<label>
<span class="td">@Application.Resources.Global.State</span>
@Html.DropDownListFor(m => m.State, (List<SelectListItem>)ViewData["State"])
</label>
<label>
<span class="td">@Application.Resources.Global.City</span>
@Html.DropDownListFor(m => m.City, (List<SelectListItem>)ViewData["City"])
</label>
If the state property returns true, then only "City" is required. If not, City is not required, then the textbox should be diabled. I'm not using EditorFor, using DropDownListFor because i'm using plain html. Can anyone help me to solve this issue? Thanks...
I'm not using EditorFor, using TextBoxFor- Where is thisTextBoxFor? I can't see it in the code you have shown. All I can see is 2 dropdown lists (which by the way are wrong because you are using the same property name for both the value and the items).Cityas first argument of your DropDown. Or rename the value in your ViewData toViewData["cities"].