我试图在我的下拉列表中将jquery验证放入完整的日历添加事件中,但我不知道为什么任何解决方案都无法正常工作..任何人都可以帮忙吗?
HTML code:
<div id="add_task_dialog_box" class="hide">
<form id="form_data" method="post" class="form-horizontal" style="display: none;">
<fieldset class="form-group">
<div class="row class1 " style="padding: 10px;">
<span><span class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<label for="dd1" style="font-weight: bold; font-size: 13px; font-type: Arial; font-family: Arial Unicode MS">
Project Name</label></span> <span class="col-lg-3 col-md-3 col-sm-3">@Html.DropDownListFor(model => model.Task_runsModel.Project_Id, db.getProjects(a), "---Select---", new { style = "width:200px;", id = "myproject", name = "Project", @class = "required" })</span>
@Html.ValidationMessageFor(model => model.Task_runsModel.Project_Id)
</span>
</div>
<div class="row class1 " style="padding: 10px;">
<span><span class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<label style="font-weight: bold; font-size: 13px; font-type: Arial; font-family: Arial Unicode MS">
Select Task</label></span> <span class="col-lg-3 col-md-3 col-sm-3">@Html.DropDownListFor(model => model.Task_runsModel.Task_Id, db.getTasks(a, c), "--Select--", new { style = "width:200px;", id = "mytask", name = "Task", @class = "required" })</span>
@Html.ValidationMessageFor(model => model.Task_runsModel.Task_Id)
</span>
</div>
<div class="row class1" style="padding: 10px;">
<span><span class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<label style="font-weight: bold; font-size: 13px; font-type: Arial; font-family: Arial Unicode MS">
Task status
</label>
</span><span class="col-lg-3 col-md-3 col-sm-9 col-xs-12 ">@Html.DropDownListFor(model => model.Task_runsModel.status, db.getStatus(), "---Select---", new { style = "width:200px", id = "taskstatus", name = "Status", @class = "required" })
</span>
@Html.ValidationMessageFor(model => model.Task_runsModel.status)
</span>
</div>
<div class="col-lg-12 col-md-3 col-sm-3 col-xs-12">
<div id="chatarea" class="dropdown-toggle" style="float: left; padding-left: 20px;
overflow-y: auto; overflow-x: auto;">
</div>
<b style="float: right; padding-right: 20px;" class="glyphicon glyphicon-chevron-down"
id="DisplayComment"></b>
</div>
@* <div id="commentdiv" class="dropdown-toggle" style=" padding-left: 20px; overflow-y: auto; overflow-x: auto;width:100%">
<ul id="current_comments" type="none" style="font-weight:bold;">
</ul>
</div>*@
<div id="textareadiv" style="padding-top:3px;">
<span class="col-lg-3 col-md-3 col-sm-9 col-xs-12" style="padding-left: 12px; width: inherit;">@Html.TextAreaFor(model => model.Task_runsModel.comment1, new { id = "comment", ariahidden = "true", placeholder = "Write comment", @class = "form-control wp-editor-area", cols = "65", rows = "3", style = " width: calc(100%);" }) </span>
</div>
</fieldset>
</form>
jquery的:
jQuery(function ($) {
// $('#form_data').validate();
$("#form_data").validate({
messages: {
Project_Id: {
required: "Eh ? empty username ?",
minLength: "At least 4 characters are necessary"
},
Task_Id: {
required: "password missing"
},
status: {
required: "please provide us your email, we promise we wont spam !",
email: "email id is not in correct format, eg: mail@yassershaikh.com"
}
}
});
答案 0 :(得分:2)
使用验证属性装饰您的模型,如下所示,您不需要在jquery中编写它是一个带有装饰属性的简单模型类,这称为模型验证的数据注释
results = [int(row[0]) for row in reader]
要进行MVC验证,请找到THIS ANSWER或THIS博客,为您的MVC项目设置MVC验证。
以下是您可以使用的一些基本数据注释
<强> DisplayName的强>
指定属性的显示名称。
<强> DisplayFormat 强>
指定属性的显示格式,例如Date proerty的不同格式。
<强>必需强>
根据需要指定属性。
<强> ReqularExpression 强>
通过指定的正则表达式模式验证属性的值。
<强>范围强>
使用指定的值范围验证属性的值。
<强> StringLength 强>
指定字符串属性的最小和最大长度。
<强>的MaxLength 强>
指定字符串属性的最大长度。