"~/Scripts/jquery.validate.min.js", "~/Scripts/jquery.validate.unobtrusive.min.js",~/Scripts/jquery.unobtrusive-ajax.min.js,"~/Scripts/ej/common/ej.unobtrusive.min.js",
|
@Styles.Render("~/Content/ej/web/default-theme/ej.web.all.min.css")
@Scripts.Render("~/Scripts/jquery-3.1.1.min.js")
@Scripts.Render("~/Scripts/jsrender.min.js")
@Scripts.Render("~/Scripts/jquery.validate.min.js")
@Scripts.Render("~/Scripts/jquery.validate.unobtrusive.min.js")
@Scripts.Render("~/Scripts/ej/ej.web.all.min.js")
@Scripts.Render("~/Scripts/ej/ej.unobtrusive.min.js") |
|
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings> |
|
public class RTEmodel
{
[AllowHtml]
[Display(Name = "Description")]
[Required(ErrorMessage = "Description is Required")]
public string description { get; set; }
} |
|
@model RTEdataAnnotation.Models.RTEmodel
<h2>RTE - Data Annotation:</h2>
<br/>
@using (Html.BeginForm())
{
@Html.LabelFor(model => model.description)
@Html.EJ().RTEFor(model => model.description)
@Html.ValidationMessageFor(model => model.description, "", new { @class = "text-danger" })
<br />
@Html.EJ().Button("btn").Size(ButtonSize.Small).Text("Post").Type(ButtonType.Submit)
} |
|
<script>
$.validator.setDefaults({
ignore: [],// To include hidden fields in validation.
});
</script> |
|
[HttpPost]
public ActionResult RichTextEditorFeatures(RTEmodel model)
{
return View();
} |
<div class="form-group-lg"> <div class="e-rowcell"> <label>@PLV.Web.Resources.Ticket.Messaggio</label> <textarea id="rteMessaggio" name="Messaggio" class="form-control" rows="8">{{: Messaggio}}</textarea> </div> </div>
$.validator.setDefaults({
ignore: [],// To include hidden fields in validation.
}); function Complete(args) {
if (args.requestType == "add") {
$("#" + this._id + "_dialogEdit").ejDialog("option", "title", "@PLV.Web.Resources.Ticket.DialogNuovoTicket")
$("#rteMessaggio").ejRTE({
allowEditing: true,
enableResize: false,
isResponsive: true,
height: "250px",
width: "250px",
locale: "@CultureInfo.CurrentCulture.TextInfo.CultureName",
toolslist: ["font", "style", "lists", "doAction", "clipboard"],
tools: {
font: ["fontSize", "fontColor"],
styles: ["bold", "italic"],
lists: ["unorderedList", "orderedList"],
doAction: ["undo", "redo"],
clipboard: ["cut", "copy", "paste"],
links: [],
images: [],
media: [],
tables: [],
view: []
},
}).data("ejRTE");
[AllowHtml] [Display(Name = "Messaggio", ResourceType = typeof(Resources.Ticket))] [Required(ErrorMessageResourceType = typeof(Resources.Ticket), ErrorMessageResourceName = "MessaggioObbligatorio")] public string Messaggio { get; set; }
|
var proxy = this;
$("#" + this._id + "EditForm").validate().settings.errorPlacement = function (error, element) {
if (element.attr("ID") == "ShipCity") {
$container = $(error).addClass("e-error");
$tail = ej.buildTag("div.e-errortail e-toparrow");
$container.prepend($tail);
$container.insertAfter(element.closest(".e-widget"))
}
} |
|
$container.offset({ left: $(element).parent().position().left + $(element).closest("td").width() |
|
function complete(args) {
if (args.requestType == "add") {
var proxy = this;
$("#" + this._id + "EditForm").validate().settings.errorPlacement = function (error, element) {
if (element.attr("ID") == "ShipCity") { // for RTE edit column
$container = $(error).addClass("e-error");
$tail = ej.buildTag("div.e-errortail e-toparrow");
$container.prepend($tail);
$container.insertAfter(element.closest(".e-widget"));
}
else { // for other edit columns
var gridObject = proxy, elements = proxy.model.scrollSettings.frozenColumns > 0 || proxy.model.editSettings.showAddNewRow ? proxy.element.find(".gridform") : $("#" + proxy._id + "EditForm");
gridObject._renderValidator(error, element); // defined in our source to perform validation
}
} |
Yes, you can use data annotations with Rich Text Editors (RTE) in your application. The Required attribute is used to specify that a property must have a non-null value. If the property is not valued and the error message is not appearing, it could be due to a few reasons.
First, make sure that the ModelState.IsValid property is being checked in your controller action method. This property is set to false if there are any validation errors in the model state. If ModelState.IsValid is false, you can return the view with the validation errors by using return View(model), where model is the object that failed validation.
Second, make sure that the validation message is being displayed in the view. You can use the @Html.ValidationMessageFor helper method to display the validation message associated with a specific property. For example, if the property is called MyProperty, you can use @Html.ValidationMessageFor(m => m.MyProperty) to display the validation message for that property.
If the above steps do not resolve the issue, there may be a problem with the way the RTE is interacting with the model binding and validation process. In this case, you may need to debug the code and/or consult the documentation or support resources for the RTE library you are using. For more Infor visit Subul