MVC 3 client-side validation on collection with data annotations — not working

后端 未结 1 1631
北荒
北荒 2021-01-16 07:34

I am trying to get client side validation to work on my model -- so far it\'s not working.

My model has a property that\'s a collection:

public class         


        
相关标签:
1条回答
  • 2021-01-16 08:28

    Try using Editor Templates in your view:

    @Html.EditorFor(x => x.newsItems)
    

    and inside ~/Views/Shared/EditorTemplates/NewsItemDetails.cshtml:

    @model AppName.Models.NewsItemDetails
    
    // bunch of stuff
    // then:
    <div class="editblock">
        @Html.TextAreaFor(model => model.newsBody, new { @class = "formtextem", id = editBoxID, rows = "10", style = "width: 54em" })
        @Html.ValidationMessageFor(model => model.newsBody)
    </div> 
    
    0 讨论(0)
提交回复
热议问题