我的模型:MVC2 - 鬼模型錯誤
public class EntryModel
{
[Required]
public string Date { get; set; }
public string Car { get; set; }
public string Engine { get; set; }
public string User { get; set; }
public int CarCod { get; set; }
public int EngineCod { get; set; }
}
筆者認爲:
<%=Html.Label("Car")%>
<%=Html.Text("Car", car,new { @class = js_car")%>
<%=Html.ValidationMessageFor(x=>x.Car) %>
<%=Html.TextBox("CarCod", carCod, new { @class = "js_car", @style = "display:none;",@id="_car_cod" })%>
我的問題:
當發佈的數據, 「CarCod」 總是在ModelState中觸發一個錯誤,因此渲染ModelState.IsValid和Html.ValidationSummary都是無用的。
我已經有這方面的解決方法(即不使用它們),但它會很高興知道爲什麼。
很難決定接受哪個答案,也謝謝。 –
我認爲我們都解決了這個問題,但是隻有一個可以被標記爲答案。丹尼爾的回答最終是正確的,我也會推薦。 –