2

I am having an issue with ASP.NET MVC3 client side validation.

My view is based on a viewmodel I've created with the following fields as Required

public class AppointmentFeedbackViewModel_Validation
{

    [Required]
    public string AttendeeName { get; set; }

    [Required(ErrorMessage = "Notes must be filled in")]
    public string Notes { get; set; }

    [Required(ErrorMessage = "Appointment status must be filled in")]
    public int AppointmentStatusId { get; set; }

    [Required]
    public int StarId { get; set; }

}

Unfortunately, a completely unrelated field SubStatusId appears as required on submitting the form.

This drop down list is passed an empty List from the controller

new List<EF.ViewModels.OpportunityConnectTypeViewModel>();

and marked up as below

<div class="display-label-styled">
    Please select another reason for this outcome
</div>
<div class="display-field-styled">
    @Html.DropDownListFor(model => model.SubStatusId, new SelectList(ViewBag.SubStatus, "ID", "StatusName"))
    @Html.ValidationMessageFor(model => model.SubStatusId)
</div>

If anybody can shed any light on this for me, I'd really appreciate it.

1
  • Can you show the whole view? Is it strongly typed? To what class? We need to see what the model type is for the view? I suspect it doesn't match your validation model. Commented Aug 16, 2011 at 18:21

1 Answer 1

4

Is SubStatusId an int? Int's are implicitly required. If you want it to not be required, declare it as a nullable int:

public int? SubStatusId;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.