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

后端 未结 1 1644
北荒
北荒 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:
    
    @Html.TextAreaFor(model => model.newsBody, new { @class = "formtextem", id = editBoxID, rows = "10", style = "width: 54em" }) @Html.ValidationMessageFor(model => model.newsBody)

    0 讨论(0)
提交回复
热议问题