我有以下的動作方法,使下面的局部視圖: -部分意見將忽略所有的模型數據註解
public ActionResult CreateVMNetwork(int vmid)
{
AssignIps vmips = new AssignIps()
{
TechnologyIP = new TechnologyIP() { TechnologyID = vmid},
IsTMSIPUnique = true,
IsTMSMACUnique = true
};
return PartialView("_CreateNetworkInfo",vmips);
}
的部分觀點是: -
model TMS.ViewModels.AssignIps
@if (this.ViewContext.FormContext == null)
{
this.ViewContext.FormContext = new FormContext();
}
@using (Ajax.BeginForm("CreateVMNetwork", "VirtualMachine", new AjaxOptions
{
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = "networktable",
LoadingElementId = "loadingimag",
HttpMethod= "POST",
OnSuccess="submitform"
}))
{
@Html.ValidationSummary(true)
@Html.HiddenFor(model=>model.TechnologyIP.TechnologyID)
@Html.AntiForgeryToken()
<div>
<span class="f">IP Address</span>
@Html.EditorFor(model => model.TechnologyIP.IPAddress)
@Html.ValidationMessageFor(model => model.TechnologyIP.IPAddress)
<input type="CheckBox" name="IsTMSIPUnique" value="true" @(Html.Raw(Model.IsTMSMACUnique ? "checked=\"checked\"" : "")) /> IP Unique. |
<span class="f"> MAC Address</span>
@Html.EditorFor(model => model.TechnologyIP.MACAddress)
@Html.ValidationMessageFor(model => model.TechnologyIP.MACAddress)
<input type="CheckBox" name="IsTMSMACUnique" value="true" @(Html.Raw(Model.IsTMSMACUnique ? "checked=\"checked\"" : "")) /> MAC Unique.
</div>
<input type="submit" value="Save" class="btn btn-primary"/>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
但視圖模型中的所有數據註釋將不火的局部視圖,該視圖AssignIps模型類是: -
namespace TMS.ViewModels
{
public class AssignIps
{
public TechnologyIP TechnologyIP { get; set; }
public bool IsTMSIPUnique { get; set; }
public bool IsTMSMACUnique { get; set; }
}
}
他TechnologyIP模型類是: -
namespace TMS.Models
{
[MetadataType(typeof(TechnologyIP_Validation))]
public partial class TechnologyIP
{}}
namespace TMS.Models
{
public class TechnologyIP_Validation
{
[Required]
public string IPAddress { get; set; }
但對TechnologyIP模型[必填]數據標註,將不會觸發對局部視圖,,任何人都可以adovce好嗎? 謝謝。
但unobrrusice驗證腳本是從主視圖填充的,它調用了部分視圖?這不夠嗎? –
如果部分在頁面之後加載(通過Ajax),則不。不顯眼的腳本只能運行一次,DOM準備就緒。 –
但我在我的部分視圖中引用了這個@section Scripts {Scripts.Render(「〜/ bundles/jqueryval」) }。所以不顯眼的腳本應該在部分視圖DOM上工作。我對嗎 ? –