0

i have a text area to which i have applied the ckeditor class. i want the text area as required field. I have added the code of the view. How can I achieve it? tried couple of solutions from CKEditor and ASP.Net MVC 3 RequiredAttribute, but no result.

@Html.LabelFor(model => model.faq_answer)
@Html.TextAreaFor(model => model.faq_answer, new { @class = "ckeditor form-control", @id = "faq_answer" })
@Html.ValidationMessageFor(model => model.faq_answer, "", new { @class = "text-danger" })

My model property

    [Display(Name ="Answer")]
    [Required(ErrorMessage ="Please Enter Answer")]
    public string faq_answer { get; set; }
Ashita Shah
  • 139
  • 1
  • 11
  • 1
    in your class add [Required] attribute to "faq_answer" field. – Jilani pasha Nov 06 '17 at 05:37
  • i have added. [Display(Name ="Answer")] [Required(ErrorMessage ="Please Enter Answer")] public string faq_answer { get; set; } – Ashita Shah Nov 06 '17 at 05:38
  • 4
    You need to configure the validator to validate hidden inputs (ckeditor hides your input and replaces it with its own html) –  Nov 06 '17 at 05:39
  • 2
    Refer [this answer](https://stackoverflow.com/questions/26379307/jquery-chosen-dropdown-validation-client-site-doesnt-work/26392882#26392882) –  Nov 06 '17 at 05:40
  • after adding that, its working, but i m facing a issue, where even if i enter the text in the ckeditor on submitting it ll show the error message and on second click the data is submitted. how can i solve this issue? – Ashita Shah Nov 06 '17 at 06:38
  • 1
    @AshitaShah, If you have a new question then you need to ask a new question (showing the relevant code and the error message) –  Nov 06 '17 at 07:36

0 Answers0