This is a migrated thread and some comments may be shown as answers.

Remote Validation not displaying the errors from

7 Answers 1027 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Yassen
Top achievements
Rank 1
Yassen asked on 01 Mar 2017, 10:36 AM

Dear all,

I had followed this useful link Remote Validation to apply the remote validation on MetaData class as follows;

Metadata

public class CoinMetadata
{
    [Required(ErrorMessageResourceType = typeof(Errors), ErrorMessageResourceName = "NameReq")]
    [Display(Name = "CoinName", ResourceType = typeof(ScreenRes))]
    [Remote("IsValidName", "Coin", ErrorMessageResourceType = typeof(Errors), ErrorMessageResourceName = "NameDuplicate")]
    // AdditionalFields="coin_id", ErrorMessageResourceType = typeof(Errors), ErrorMessageResourceName = "NameDuplicate")
    public string name { get; set; }
}

 

The Controller:

public JsonResult IsValidName(string name)
{
    bool found = db.IGL_coin.Any(name => name.name == name);
    if (!found)
    {
        return Json(true, JsonRequestBehavior.AllowGet);
    }
    return Json(false, JsonRequestBehavior.AllowGet);
}

The error message from resource file doesn't show up, instead It shows false.

How can I make it works?

7 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 03 Mar 2017, 07:36 AM
Hello Yassen,

After inspecting the example I noticed that IsValidName is returning false instead of the validation message like in the provided example:

string suggestedName = String.Format(CultureInfo.InvariantCulture,
                "{0} is not available.", ProductName);
.....
return Json(suggestedName, JsonRequestBehavior.AllowGet);

Please check if returning a string message instead of false will resolve the issue.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Yassen
Top achievements
Rank 1
answered on 04 Mar 2017, 08:34 PM

Hello Stefan,

It does as a matter of fact !!,

My question is that Why it can not return the error message from the data annotation ?

regards

0
Stefan
Telerik team
answered on 07 Mar 2017, 07:08 AM
Hello Yassen,
 
The error message which will be should is a custom one and it is set in the validation controller.

Please advise if the desired result is to return different message that the one set in the validation controller?

Also, I can suggest checking the other available approaches for validation:

http://docs.telerik.com/aspnet-mvc/getting-started/validation?wcmmode=disabled#common-scenarios

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Yassen
Top achievements
Rank 1
answered on 10 Mar 2017, 08:33 AM

Helllo Stefan,

Yes, I need to return the message on the MetaData class defined by DataAnnotation attribute

1.public class CoinMetadata
2.{
3.    [Required(ErrorMessageResourceType = typeof(Errors), ErrorMessageResourceName = "NameReq")]
4.    [Display(Name = "CoinName", ResourceType = typeof(ScreenRes))]
5.    [Remote("IsValidName", "Coin", ErrorMessageResourceType = typeof(Errors), ErrorMessageResourceName = "NameDuplicate")]
6.    // AdditionalFields="coin_id", ErrorMessageResourceType = typeof(Errors), ErrorMessageResourceName = "NameDuplicate")
7.    public string name { get; set; }
8.}

 

have a look at line number 5, the error message comes from a resource file.

Best regards

0
Stefan
Telerik team
answered on 13 Mar 2017, 02:25 PM
Hello Yassen,

Please have in mind that the provided demo example is completely custom and it is based on the following MSDN documentation, and it is not directly related to Kendo UI:

https://msdn.microsoft.com/en-us/library/gg508808(vs.98).aspx

The message is coming from data--remote
  
messages: {
 remote: function (input) {
  return input.attr("data-val-remote");
 }
}

Which respectively is coming from the success function:

success: function (data) {
 if (data == true) {
  input.attr("data-val-remote", "");
 }
 else {
  input.attr("data-val-remote", data);
 }
 input.attr("data-val-remote-recieved", true);
 validator.validateInput(currentInput);
 
                        }

If the success is not set, the standard data--remote attribute will be shown.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Yassen
Top achievements
Rank 1
answered on 16 Mar 2017, 02:36 PM

Hello Stefan,

Appreciate your rely.

I have a very basic scenario, what should I do to show the errors from the resources attached using data annotation?

Regards

0
Stefan
Telerik team
answered on 20 Mar 2017, 10:36 AM
Hello Yassen,

The link provided in a previous reply demonstrates the most common scenarios when working with validation and data annotations:

http://docs.telerik.com/aspnet-mvc/getting-started/validation?wcmmode=disabled#common-scenarios

Please advise if more information is needed on this matter.

Regards,
Stefan
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
Yassen
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Yassen
Top achievements
Rank 1
Share this question
or