2016-12-02 5 views
1

私は次のモデルプロパティを持っています。その1つは、SQL Serverにntextカラムを生成するprojectDescriptionです。ntextプロパティのASP.NET MVC textareaタグヘルパーが機能していません

モデル:次のように

--some other properties here.... 

[Display(Name = "Project Title")] 
     [Column(TypeName = "varchar(125)")] 
     public string ProjectTitle { get; set; } 

[Column(TypeName = "ntext")] 
public string ProjectDesctiption { get; set; } 

--some other properties here.... 

このプロパティはViewtextareaタグにバインドされています。しかし、DbからのProjectDesctiption列の実際のデータを表示する代わりに、次の図に示すように、ページの表示のhtmlソースページ全体を表示します。他のタグは、下の同じ画像のProjectTitleフィールドに示すように、データを正しく表示します。問題はntextデータ型とASP Tag helper for textareaに関連していると思います。私は、ProjectDescription内のいくつかのデータセルの最大長がかなり大きいことをデータベースでチェックしました。約61968文字です。しかし、この列のデータを縦横のスクロールバーで長さと幅が合理的なテキストエリアで表示したい場合は、このフィールドのデータを一瞥してプロジェクトの説明(たとえば)や何らかの目的のためにテキスト領域からデータをコピー/通過させることができる。 質問:どうすればこの目標を達成できますか?

ビュー

---some html here..... 
<div class="form-group"> 
     <label asp-for="ProjectTitle" class="col-md-2 control-label"></label> 
     <div class="col-md-10"> 
      <input asp-for="ProjectTitle" class="form-control" /> 
      <span asp-validation-for="ProjectTitle" class="text-danger"></span> 
     </div> 
    </div> 
    <div class="form-group"> 
     <label asp-for="ProjectDesctiption" class="col-md-2 control-label"></label> 
     <div class="col-md-10"> 
      <textarea asp-for="ProjectDesctiption" class="form-control" rows="6" cols="15" /> 
      <span asp-validation-for="ProjectDesctiption" class="text-danger"></span> 
     </div> 
    </div> 
...some other html here... 

enter image description here

+0

サイドノートにコード - [ドキュメント](https://msdn.microsoft.com/en-AU/library/ms187993.aspx)_IMPORTANTから! ntext、text、およびimageデータ型は、将来のバージョンのSQL Serverでは削除されます。これらのデータ型の使用は避けてください。 –

+0

@StephenMuecke良い点。 nvarcharを使用する魅力的な理由がない限り、それをnvarchar(max)以上に変更する必要があります(varchar(max))。問題のDbは、実際にはMs Access Dbからの変換であり、変換した者は、おそらくAccessのテキスト列をSQL Serverのntextに自動的に変換するMicrosoftの移行ツールを使用したと仮定しています。しかし、私たちの場合、nvarcharが必要かvarchar(最大)で十分かどうかを調べます。 – nam

答えて

2

<textarea>は、自己終了タグではなく、あなたが '閉じた' していないので、そのタグを次のHTMLを表示します。

変更あなたは

<textarea asp-for="ProjectDesctiption" class="form-control" rows="6" cols="15"></textarea> 
+2

また、 'ProjectDescription'に名前を変更することをお勧めします:) –

+0

あなたの提案はうまくいきました(ありがとう、スペルミスをキャッチ)。 – nam

関連する問題