忍者ブログ
[212]  [211]  [210]  [209]  [203]  [207]  [205]  [204]  [196]  [193]  [190
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

・ダイナミック出力

int hour = DateTime.Now.HOur;
ViewBag.Msg= hour <12 ? "おはよう":"こんにちは"; 


・エラーチェック

1.モデルに
using System.ComponentModel.DataAnnotations;

[Rewuired(ErrorMessage = "")]
public string Name{get;set;}

2.コントローラーに
if(ModelIState.IsValid){

}else{ //エラーの時そのまま戻る
  return Vuew();
}

3.Viewに
@using (Html.BeginForm()){

    @Html.Validation.Summary() 

}


・エラー箇所を色表示
1.Contentにstyles.cssを追加
.field-validation-error {color : #f00;}
.field-validation-valid {disolay: none;}
.input-validation-error {border:1px solid #f00; background-color:#fee;}
.validation-summary-errors {font-weight:bold; color:#f00;}
.validation-summary-valid {display: none;}

2.Viewに
<head>
 <link rel ="stylesheet" type = "text/css" href ="~/Content/styles.css"/>









拍手

PR
カレンダー
05 2025/06 07
S M T W T F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
フリーエリア
最新CM
[03/10 DORA]
最新TB
プロフィール
HN:
dorabu
性別:
非公開
バーコード
ブログ内検索
P R
Copyright © ドラブーのアンドロイドとIoTなブログ All rights reserved. / Template by 四季. / Material by てんせん.

忍者ブログ [PR]