- Home
- Forum
- ASP.NET Core - EJ 2
- Add validation error message using data annotation modal in partial view
Add validation error message using data annotation modal in partial view
Hi,
I researched how to put the error message in a add/edit custom partial view, but I the example below does not use data annotation. How do I use the class model feature to show the error message? I'm using a partial custom view to edit and add a record.
https://www.syncfusion.com/forums/143977/how-to-set-validation-rules-for-custom-dialog-templates
class Pedido
{
[Required]
[Display(Name = "Cliente")]
public string ClienteID { get; set; }
}
my custom partial view
@model models.Pedido
<div>
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class=" col-12 wrapper_field">
<ejs-dropdownlist cssClass="e-outline"
floatLabelType="Auto"
id="ClienteID"
ejs-for="ClienteID"
value="@Model.ClienteID"
dataSource="@ViewBag.ClienteID"
popupWidth="400px"
placeholder="Cliente"
popupHeight="220px">
<e-dropdownlist-fields text="Nome"
value="ClienteID">
</e-dropdownlist-fields>
</ejs-dropdownlist>
<span asp-validation-for="ClienteID" class="text-danger"></span>
</div>
</div>
<ejs-scripts></ejs-scripts>
my view to call a partial view
function actionComplete1(args) {
if ((args.requestType === 'beginEdit' || args.requestType === 'add')) {
let spinner = ej.popups.createSpinner({ target: args.dialog.element });
ej.popups.showSpinner(args.dialog.element);
var dialog = args.dialog;
dialog.width = $(document).width() * 0.8;
// change the header of the dialog
dialog.header = args.requestType === 'beginEdit' ? 'Editar Secagem ' + args.rowData['Numero'] : 'Nova Secagem';
}
if (args.requestType === 'beginEdit') {
var ajax = new ej.base.Ajax({
url: "/Pedido/EditPartial", //render the partial view
type: "POST",
contentType: "application/json",
data: JSON.stringify({ value: args.rowData })
});
ajax.send().then(function (data) {
appendElement1(data, args.form); //Render the edit form with selected record
args.form.elements.namedItem('DataPedido').focus();
ej.popups.hideSpinner(args.dialog.element);
}).catch(function (xhr) {
console.log(xhr);
ej.popups.hideSpinner(args.dialog.element);
});
}
if (args.requestType === 'add') {
var ajax = new ej.base.Ajax({
url: "/Pedido/AddPartial", //render the partial view
type: "POST",
contentType: "application/json",
data: JSON.stringify({ value: args.rowData })
});
ajax.send().then(function (data) {
appendElement1(data, args.form); //Render the edit form with selected record
args.form.elements.namedItem('DataPedido').focus();
ej.popups.hideSpinner(args.dialog.element);
}).catch(function (xhr) {
console.log(xhr);
ej.popups.hideSpinner(args.dialog.element);
});
}
}
function appendElement1(elementString, form) {
form.querySelector("#dialogTemp").innerHTML = elementString;
var script = document.createElement('script');
script.type = "text/javascript";
var serverScript = form.querySelector("#dialogTemp").querySelector('script');
script.textContent = serverScript.innerHTML;
document.head.appendChild(script);
serverScript.remove();
}
SIGN IN To post a reply.
5 Replies
1 reply marked as answer
RS
Rajapandiyan Settu
Syncfusion Team
May 26, 2021 11:53 AM UTC
Hi Roberto,
Thanks for contacting Syncfusion support.
Currently, the Data Annotation support is not available for Grid in ASP.NET Core. We have already considered this as a feature request (“Provide Data-Annotation support for ASP.Net Core”) from our end. At the planning stage for every release cycle, we review all open features and identify features for implementation based on specific parameters including product vision, technological feasibility, and customer interest. So this feature will be implemented in any of our upcoming releases.
You can now track the current status of your request, review the proposed resolution timeline and contact us for any further inquiries through the following feedback link,
For performing client-side validation, please refer to the following help documentation link,
Documentation:
Add validation for custom editors: https://ej2.syncfusion.com/aspnetcore/documentation/grid/edit/#adding-validation-rules-for-custom-editors
Regards,
Rajapandiyan S
Marked as answer
Hi,
I'm having the same problem, on the same code, but ASP.NET for the MVC 5 EJ2 version, is there any news about it?
RS
Rajapandiyan Settu
Syncfusion Team
June 28, 2021 01:24 PM UTC
Hi Pio Luca Valvona,
Thanks for contacting Syncfusion support.
Based on your requirement, you want to perform validation using Data-Annotation in the MVC project. You can achieve your requirement by using following code example.
|
[index.cshtml]
@using dotnet_mvc_sample.Controllers;
@{
List<object> toolbarItems = new List<object>();
toolbarItems.Add("Add");
toolbarItems.Add("Edit");
toolbarItems.Add("Delete");
toolbarItems.Add("Update");
toolbarItems.Add("Cancel");
}
// bind the class model to the Grid
@(Html.EJS().Grid<HomeController.BigData>("Grid").DataSource((IEnumerable<object>)ViewBag.DataSource).Columns(col =>
{
col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("150").Add();
col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add();
col.Field("Freight").HeaderText("Freight").EditType("numericedit").Width("160").Format("N2").Add();
col.Field("ShipCountry").EditType("dropdownedit").HeaderText("Ship Country").Width("140").Add();
}).AllowPaging().PageSettings(page => page.PageCount(2)).EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true); }).Toolbar(toolbarItems).Render())
|
|
[HomeControllers.cs]
public class BigData
{
public BigData()
{
}
-----
[Key]
public int? OrderID { get; set; }
[MinLength(3, ErrorMessage = "Need atleast 3 characters")]
[MaxLength(10, ErrorMessage = "Characters exceed")]
public string CustomerID { get; set; }
[Required]
public string ShipCountry { get; set; }
public int? ID1 { get; set; }
public int? ID2 { get; set; }
public int? EmployeeID { get; set; }
[Range(0, 100)]
public double? Freight { get; set; }
public string ShipCity { get; set; }
public bool Verified { get; set; }
public DateTime? OrderDate { get; set; }
public string ShipName { get; set; }
public DateTime ShippedDate { get; set; }
public string ShipAddress { get; set; }
}
|
Please get back to us if you need further assistance with this.
Regards,
Rajapandiyan S
NS
Nayas Subramanian
August 23, 2022 04:58 AM UTC
I am having issues with data annotation validation in partial views. Do you have any fix for this issue? If yes, can you share how to implement it?
RS
Rajapandiyan Settu
Syncfusion Team
August 24, 2022 12:43 PM UTC
Hi Nayas,
Thanks for contacting Syncfusion support.
Kindly share the following details to proceed further on your requirement.
- Which platform do you have used (ASP NET MVC/ ASP NET CORE)?
- Share the complete Grid code files.
- Share the Grid script and Syncfusion DLL version.
- If possible, share the issue reproducible sample which will be very helpful for us.
Regards,
Rajapandiyan S
SIGN IN To post a reply.
- 5 Replies
- 4 Participants
- Marked answer
-
RO Roberto
- May 25, 2021 11:03 PM UTC
- Aug 24, 2022 12:43 PM UTC