This is a migrated thread and some comments may be shown as answers.

[Solved] ClientSide validation issues with dropdownlistfor

1 Answer 92 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tyler
Top achievements
Rank 1
Tyler asked on 16 May 2012, 09:34 PM
Hi,

I have an issue with telrik's dropdownlistfor helper. If I use this helper, does not validate on the client site, it will post then validate.

When I use MVC's standard html.dropdownlistfor helper all clientside validation holds true, and prevents a user from submitting.

Is this a known bug, or am I doing something wrong? I've tried passing an instance of the model and converting the model's property to be nullable. No matter what, client-side validation is never triggered. 

My view:

@Html.Telerik().DropDownListFor(model => model.BusinessUnitId).BindTo((SelectList)ViewData["BusinessUnits"]).HtmlAttributes(new { style = "width:400px; white-space:nowrap;" }).DropDownHtmlAttributes(new { style = "width:400px; white-space:nowrap;" })

My Model:
   public class ContractViewModel
    {
 [Required]
        public int BusinessUnitId { get; set; }
}

I am also using the latest version of the MVC controls.

Thanks in advance!

1 Answer, 1 is accepted

Sort by
0
Pradeep
Top achievements
Rank 1
answered on 28 May 2012, 07:24 AM
Even I am facing the same problem. Following is how I am rendering the view:

@Html.LabelFor(M => M.CancellationReasons)
                @{Html.Telerik().DropDownListFor(model => model.ReasonId)
                    .BindTo(Model.CancellationReasons)
                    .Render();
                    }
@*Validation are working fine with html dropdown but not with telerik dropdown*@
@*Html.DropDownListFor(model => model.ReasonId, Model.CancellationReasons, "Please select")*@
@Html.ValidationMessageFor(model => model.ReasonId)

Following is my model

public class CancelJobViewModel
    {
        public CancelJobViewModel()
        {
            
        }      
 
        [Display(Name = "CancellationReasons", ResourceType = typeof(Resources.Resources))]
        public SelectList CancellationReasons { getset; }
 
        [Required(ErrorMessageResourceName = "Required", ErrorMessageResourceType = typeof(Resources.ValidationMessages))]
        public int? ReasonId { getset; }
}

Anything that I am missing here?
Tags
ComboBox
Asked by
Tyler
Top achievements
Rank 1
Answers by
Pradeep
Top achievements
Rank 1
Share this question
or