Greetings,
I would like to know if it's possible to use remote validation with the rich text box component.
More info about remote validation( Model validation in ASP.NET Core MVC | Microsoft Docs)
Atm my RTE is rendered like this:
<ejs-richtexteditor id="RedenOmschrijving" value="@Model.RedenOmschrijving">
<e-richtexteditor-pastecleanupsettings Prompt="false" deniedTags="@ViewBag.deniedTags" keepFormat="false"></e-richtexteditor-pastecleanupsettings>
<e-richtexteditor-toolbarsettings items="@ViewBag.tools"></e-richtexteditor-toolbarsettings>
<e-content-template>
</e-content-template>
</ejs-richtexteditor>
I think i need to use asp-for for being able to use the remote validation, but that doesn't work.
I need remote validation since i need 2 properties to be checked.
Can you guys help me?
|
<form asp-controller="Home" asp-action="Index" method="post">
<ejs-richtexteditor id="Rte1" ejs-for="Rte">
</ejs-richtexteditor>
<span asp-validation-for="Rte" class="text-danger"></span>
<br />
<button type="submit">Save</button>
</form>
<script src=https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/jquery.validate.min.js></script>
<script src=https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js></script>
<script>$.validator.setDefaults({ignore: [],});</script>
|
|
namespace WebApplication2.Models
{
public class EmployeeInputModel
{
[Required]
[Remote(action: nameof(HomeController.ValidateRte),
controller: "Home",
ErrorMessage = "The RTE value can't be active",
HttpMethod = nameof(HttpMethod.Get))]
public string Rte { get; set; }
}
} |
|
public class HomeController : Controller
{
public IActionResult Index()
{
return View(new EmployeeInputModel());
}
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Index(EmployeeInputModel model)
{
if (!ModelState.IsValid)
{
return View(model);
}
var json = JsonConvert.SerializeObject(model);
return Content(json);
}
public JsonResult ValidateRte(string rte)
{
if (rte.ToLower() == "<p>active</p>")
return Json(data: false);
return Json(data: true);
}
|