2011-01-07 95 views
1

我已經構建了一個用於數據輸入的Web應用程序(數據類型不重要)。該站點的一部分允許用戶動態添加數據行。對於靜態輸入字段,我使用DataAnnotations以便我可以管理字段的驗證。當我嘗試爲動態字段做類似的事情時,驗證似乎不起作用。驗證動態行

這是我的應用程序的(一般)設置。

[Data Input Page] -> [Partial Page for Dynamic Table] -> [Table is made up of individual rows (partial page)] 

每個頁面都是強類型的。

這裏是一個獨立的行的例子,部分頁面:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Models.Person>" %> 

<tr> 
<% using (Html.BeginCollectionItem("People")) { %> 
    <td class="ui-widget-content"><%= Html.TextBoxFor(model => model.Name) %></td> 
    <td class="ui-widget-content"><%= Html.TextBoxFor(model => model.Age) %></td> 
    <td class="ui-widget-content"><%= Html.TextBoxFor(model => model.PhoneNumber) %> 

    // [Cut] Some other, unimportant information here which allows a new row to be added. 
</tr> 

// This portion is not working - it does work with static fields. 
<div class="validation"> 
    <div><%: Html.ValidationMessageFor(model => model.Name)%></div> 
    <div><%: Html.ValidationMessageFor(model => model.Age)%></div> 
    <div><%: Html.ValidationMessageFor(model => model.PhoneNumber)%></div> 
</div> 

任何洞察得到驗證與DataAnnotations工作(所以它是相同/相似於什麼我已經在做)會非常感激。

回答

1

Steve Sanderson blogged about validation在這種情況下。

+0

謝謝(並接受)。這確實回答了這個問題。但是,瘋狂的黑客。 – JasCav 2011-01-18 21:15:50