一見非常に単純に見えるものが機能していません。
私はモデルを持っています
public class Name: Entity
{
[StringLength(10), Required]
public virtual string Title { get; set; }
}
public class Customer: Entity
{
public virtual Name Name { get; set; }
}
ビューモデル
public class CustomerViweModel
{
public Customer Customer { get; set; }
}
ビュー
<% using(Html.BeginForm()) { %>
<%= Html.LabelFor(m => m.Customer.Name.Title)%>
<%= Html.TextBoxFor(m => m.Customer.Name.Title)%>
<button type="submit">Submit</button>
<% } %>
そしてコントローラー
[HttpPost]
public ActionResult Index([Bind(Prefix = "Customer")] Customer customer)
{
if(ModelState.IsValid)
Save
else
return View();
}
タイトルとして何を入力しても (null、または 10 文字を超える文字列)、ModelState.IsValid は常に true です。Customer オブジェクトの Title フィールドに値があるため、データは渡されますが、検証されませんか?
手がかりはありますか?