我在asp.net mvc-4中有以下主视图: -
@model TMS.ViewModels.SwitchJoin
@Ajax.ActionLink("Add Port Info", "CreatePort","Switch",
new { switchid = Model.Switch.SwitchID },
new AjaxOptions {
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "AssignPort" ,
LoadingElementId = "progress"
}
)
</p>
//code goes here
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
以下两个部分视图; -
@model TMS.Models.TMSSwitchPort
@using (Ajax.BeginForm("CreatePort", "Switch", new AjaxOptions
{
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = "Porttable",
LoadingElementId = "loadingimag",
HttpMethod= "POST",
OnSuccess="submitform"
}))
{
@Html.ValidationSummary(true)
@Html.HiddenFor(model=>model.SwitchID)
@Html.Partial("_CreateOrEditPort", Model)
<input type="submit" value="Save" class="btn btn-primary"/>
}
&安培;&安培;&安培;
@model TMS.Models.TMSSwitchPort
@Html.AntiForgeryToken()
<div>
<span class="f">Device Tag</span>
@Html.TextBoxFor(model => model.Technology.Tag)
@Html.ValidationMessageFor(model => model.Technology.Tag)
<span class="f"> Port Number</span>
@Html.TextBoxFor(model => model.PortNumber)
@Html.ValidationMessageFor(model => model.PortNumber)
</div>
我有以下Meta类型Model类: -
public class TMSSwitchPort_Validation
{
[Required]
public string PortNumber { get; set; }
}
}
但是在__CreateOrEditPort局部视图中,所需的验证不会触发?有人可以建议吗?
答案 0 :(得分:0)
回答@ develiper10214是对的,但你也写了MetaType模型类。我觉得,你想要你的类的MetadataType类。
如果是的话。你需要看一些规则。
示例:
namespace TMS.Models
{
public partial class TMSSwitchPort
{
public string PortNumber { get; set; }
}
}
另一堂课:
namespace TMS.Models
{
[MetadataType(typeof(TMSSwitchPortMetadata))]
public partial class TMSSwitchPort
{
//Nothing
}
public class TMSSwitchPortMetadata
{
[Required]
public string PortNumber { get; set; }
}
}