2012-04-18 13 views
1

タイトルとNewsContentの検証に失敗した以下のビューがあります。タイトルの検証は機能しますが、NewsContentは機能しません。どのように私はそれを修正することができます。MVC3検証の問題

@model Foo.NewsViewModel 
@{ 
    ViewBag.Title = "Create"; 
} 



@using (Html.BeginForm("Create", "News", FormMethod.Post, new { enctype = "multipart/form-data" })) 
{ 
    <div> 
     <fieldset> 
      <legend>Category Information</legend> 
      <div class="editor-label"> 
       @Html.LabelFor(m => m.News.Title) 
      </div> 

      <div class="editor-field"> 
       @Html.TextBoxFor(m => m.News.Title) 
       @Html.ValidationMessageFor(m => m.News.Title) 
      </div> 
       <div class="editor-label"> 
       @Html.LabelFor(m => m.News.NewsContent) 
      </div> 

      <div class="editor-field" id="container"> 
       @Html.TextAreaFor(m => m.News.NewsContent) 
       @Html.ValidationMessageFor(m => m.News.NewsContent) 
      </div> 
      <div class="editor-label"> 
       @Html.LabelFor(m => m.News.Thumbnail) 
      </div> 

      <div class="editor-field"> 
       <input type="file" name="files" id="thumbnail" /> 
      </div> 

      <div class="editor-label"> 
       @Html.LabelFor(m => m.News.Image) 
      </div> 

      <div class="editor-field"> 
       <input type="file" name="files" id="original" /> 
      </div> 

      <div class="editor-label"> 
       @Html.Label("SelectedCategoryId") 
      </div> 

      <div class="editor-field"> 
       @Html.DropDownListFor(m => m.SelectedCategoryId, Model.Categories) 
      </div> 

      <div class="editor-label"> 
       Publish 
      </div> 

      <div class="editor-field"> 
       @Html.CheckBoxFor(m => m.News.Published, new { @checked = "checked" }) 
      </div> 

      <p> 
       <input type="submit" value="Create" /> 
      </p> 
     </fieldset> 
    </div> 
} 

とこちらのモデルです|:

public class News : IStorable 
    { 
     [Required] 
     [Display(Name = "Title")] 
     public virtual string Title { get; set; } 

     [Required] 
     [Display(Name = "Content")] 
     public virtual string NewsContent { set; get; } 
...... 
+0

私はどのEntity Frameworkの「味」WYSIWYG –

+0

FCKEditorのようなニュースコンテンツリッチテキストエリアであるあなたが使用していますか? – DarthVader

+0

を追加するでしょBT、それは今だけのテキストエリアだなど – NSGaga

答えて

3

が問題:タイトルの検証作品ではなく、NewsContent。

ようにモデルを変更し

検証はここ

はそれを動作させるためのコードがある、なぜなら「NewsContent」プロパティをレンダリングするHtml.TextAreaFor()ヘルパーを使用するのでは、動作していません

[NewsContent]プロパティを[DataType]属性でデコレートし、データ型を 'MultilineText'に設定します。これは、このプロパティのエディタが複数行のテキスト入力であることを示します。代わりHtml.TextAreaForのビュー使用Html.EditorFor()ヘルパー(IN

public class News : IStorable 
{ 
    [Required] 
    [Display(Name = "Title")] 
    public virtual string Title { get; set; } 

    [Required()] 
    [Display(Name = "Content")] 
    [DataType(DataType.MultilineText)] 
    public virtual string NewsContent { set; get; } 
    //.... 
} 

) 'News.NewsContent' プロパティのため。

//.... 
<div class="editor-label"> 
    @Html.LabelFor(m => m.News.NewsContent) 
</div> 

<div class="editor-field" id="container"> 

    @*@Html.TextAreaFor(m => m.News.NewsContent)*@ 

    @Html.EditorFor(m => m.News.NewsContent) 
    @Html.ValidationMessageFor(m => m.News.NewsContent) 
</div> 
//.... 
+0

が働いた。驚くばかり。ありがとう。 – DarthVader