你好嗎?我試圖在ASP NET MVC中驗證表單。asp net mvc部分視圖驗證
我
我的問題是,當我提交表單,只有父親視圖的控制得到確認的局部視圖「地址」,我重用一些實體,如公司,個人等,在局部視圖中的人不會。
下面是一些代碼,我希望你能geive我的手
人稱視角
@model Entities.Person
@using (Html.BeginForm("Create", "Person", FormMethod.Post))
{
<table>
<tr>
<td>
@Html.LabelFor(model => model.FirstName)
<div class="control">
@Html.TextBoxFor(model => model.FirstName, new { @maxlength = 7, @class = "numeric"})
@Html.ValidationMessageFor(model => model.FirstName)
</div>
<div class="spacer-short"></div>
</td>
<td>
@Html.LabelFor(model => model.LastName)
<div class="control">
@Html.TextBoxFor(model => model.LastName, new { @maxlength = 7, @class = "numeric"})
@Html.ValidationMessageFor(model => model.LastName)
</div>
<div class="spacer-short"></div>
</td>
</tr>
</table>
@{ Html.RenderAction("Index", "Address", new {id = Model.AddressId});} //Renders the Address form part
<div class="spacer"></div>
<button type="submit" data-button="true" data-button-icon="ui-icon-disk" class="">Create</button>
<button type="button" data-button="true" data-button-icon="ui-icon-circle-close" class="button-cancel">Cancel</button>
}
地址檢視
@model Entities.Address
<table>
<tr>
<td>
@Html.LabelFor(model => model.Street)
<div class="control">
@Html.TextBox("Address.Street", Model.Street)
@Html.ValidationMessage("Address.Street")
</div>
<div class="spacer-short"></div>
</td>
<td>
@Html.LabelFor(model => model.Number)
<div class="control">
@Html.TextBox("Address.Number", Model.Number)
@Html.ValidationMessage("Address.Number")
</div>
<div class="spacer-short"></div>
</td>
</tr>
</table>
然後,我有一些驗證的元數據([必填] )爲人和地址字段
後您是否嘗試過使用具有的RenderAction相同的結果之前,@ Html.Partial( 「地址」) – 2013-03-18 17:18:43