4

Ville+ Code-postal+Paysが一意であることを検証したいと思います。

検証に合格しない場合は、フィールドを無効としてマークしたいと思います (通常は赤)。

ここに画像の説明を入力

私はすでに以下のような最初の実装を試みています:

public class CityEditViewModel
{
    public int CityID { get; set; }

    [Required, Remote("CityAlreadyExists", "City", AdditionalFields = "CountryID, CityID, PostCode", ErrorMessageResourceName = "CityAlreadyExists", ErrorMessageResourceType = typeof(UserResource))]
    [Display(Name = "City", ResourceType = typeof(UserResource))]
    public string CityName { get; set; }

    [Required, Remote("CityAlreadyExists", "City", AdditionalFields = "CountryID, CityID, CityName", ErrorMessageResourceName = "CityAlreadyExists", ErrorMessageResourceType = typeof(UserResource))]
    [Display(Name = "PostCode", ResourceType = typeof(UserResource))]
    public string PostCode { get; set; }

    [Required, Remote("CityAlreadyExists", "City", AdditionalFields = "CityName, PostCode, CityID", ErrorMessageResourceName = "CityAlreadyExists", ErrorMessageResourceType = typeof(UserResource))]
    [Display(Name = "Country", ResourceType = typeof(UserResource))]
    public int CountryID { get; set; }

    public List<SelectListItem> Countries { get; set; }
}

しかし、実際に何かを変更するまで、すべてのフィールドはチェック (検証) されません。3 つのフィールドのいずれかを変更するたびに、3 つのフィールドすべてが検証され、必要に応じて赤でマークされるソリューションが必要です。

他の Stackoverflow の投稿を既に確認しましたが、特定の問題の解決策が見つかりませんでした。

ご協力いただきありがとうございます。

4

2 に答える 2

2

私も同様のシナリオを持っていましたが、これは私が進むのに役立ちました

$("#FirstName").change(function () {
        $('#CardNumber').removeData('previousValue');
        $('#CardNumber').valid();
  });

リモート検証を使用した複数フィールドの検証

于 2012-11-12T21:54:56.153 に答える