0
我有我的ASP.NET MVC 4網站上驗證jQuery的問題。這裏的形式:jQuery驗證不與TinyMCE
@model QuestionModel
@using (Html.BeginForm()) {
@Html.ValidationSummary("Please correct the errors and try again.")
@Html.LabelFor(m => m.Author)
@Html.EditorFor(m => m.Author)
@Html.LabelFor(m => m.Question)
@Html.TextAreaFor(m => m.Question, new { @class = "tinymce" })
@Html.LabelFor(m => m.Answer)
@Html.TextAreaFor(m => m.Answer, new { @class = "tinymce" })
}
這裏的與數據註解的模型:
public class QuestionModel
{
[Required]
public string Author { get; set; }
[Required]
public string Question { get; set; }
[Required]
public string Answer { get; set; }
}
在Firebug的控制檯I可以驗證單獨的形式的每一個元素:
> $('#Author').valid()
true
> $('#Question').valid()
true
> $('#Answer').valid()
false
原因應答字段無效是因爲它是空白的:
> $('#Author').val()
"David Bowie"
> $('#Question').val()
"<p>What is my best song?</p>"
> $('#Answer').val()
""
然而,顯然jQuery驗證認爲形式作爲一個整體是有效的:
> $('form').valid()
true
這是爲什麼?
這是您網頁上唯一的表單嗎? – jrummell 2014-08-28 20:28:25
很奇怪。你可以檢查textarea @ Html.TextAreaFor(m => m.Answer,new {@class =「tinymce」})生成的標記,看看生成的ID是否爲Answer? – HaBo 2014-08-28 20:29:21
@ jrummell是的。 – 2014-08-28 20:48:19