sitefinity验证数据视图 [英] sitefinity Validation data view
问题描述
我不使用sitefinity表单控件来构建此MVC表单.我想将验证添加到名字"文本框.在模型中,我在视图所使用的视图模型的属性上具有[Required]属性.我只得到红色文本 FirstName字段为必填字段.
,但我希望文本框和标签也为红色.我是否需要另一个类用于TextBox或带有Bootstrap的东西?
I am building this MVC form not using the sitefinity form control. I wanted to add validate to the First Name TextBox. In the model I have [Required] attribute on the property in the view model used by the view. I only get the red text The FirstName field is required.
but I wanted the textbox and label to be red as well. Is there another class I need to use for the TextBox or anything with Bootstrap ?
查看
@Html.Script(ScriptRef.JQueryValidate, "top", true)
@{
HtmlHelper.ClientValidationEnabled = true;
HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
}
查看
<div class="form-group row">
<div class="col-sm-6">
@Html.LabelFor(model => model.FirstName)
@Html.TextBoxFor(x => x.FirstName, new { @class = "form-control", @id = "txtFirstName" })
@Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
</div>
<div class="col-md-6">
@Html.LabelFor(model => model.LastName)
@Html.TextBoxFor(x => x.LastName, new { @class = "form-control", @id = "txtLastName" })
@Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
</div>
</div>
型号
[Required]
public string FirstName { get; set; }
推荐答案
通常,要在页面上初始化jquery validate插件,您将需要执行以下操作
Normally, to initialize the jquery validate plugin on the page, you will need to do something like this
<script>
$(function() {
$("form").validate();
})
</script>
这篇关于sitefinity验证数据视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!