22

次のようなビューモデルがある場合:

public class Car

{

     Wheel CarWheel {get;set;}
     Body CarBody {get;set;}

}

私の Wheel クラスと Body クラスは次のようになります。

public class Wheel
{
    int Number {get;set;}
    string WheelType {get;set;}
}

public class Body
{
    int Number {get;set;}
    string BodyType {get;set;}
}

そして、ホイール番号が 1 未満のモデル エラーを追加します。

ModelState.AddModelError(???, "Error! You must have at least one wheel to avoid abrasion on your bottom");

エラーが Body クラスではなく、特に Wheel クラスにあることを指定するにはどうすればよいですか?

4

3 に答える 3

3
ModelState.AddModelError("Car_CarWheel_Number", "Error! You must have at least one wheel to avoid abrasion on your bottom");

また

ModelState.AddModelError("", "Error! You must have at least one wheel to avoid abrasion on your bottom \n\r Error 2");
于 2012-08-21T12:33:58.013 に答える
1

ブライアンの答えまたはデータ注釈を使用してみてください。

range 属性が適切に機能するはずですが、必要に応じて独自の属性を作成することもできます。

于 2012-08-22T10:10:52.793 に答える