1

我有以下模型类:-

public class TMSServer_Validation
{
    [Required]
    public string ILOIP { get; set; }
}

以及以下观点:-

@model TMS.ViewModels.ServerJoin
<div >
  <span class="f">  ILOIP</span>

    @Html.EditorFor(model =>model.Server.ILOIP)
    @Html.ValidationMessageFor(model =>model.Server.ILOIP)
</div>

以及以下后操作方法:-

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(ServerJoin sj, FormCollection formValues)
{
    //code goes here..
    repository.InsertOrUpdateServer(sj.Server, User.Identity.Name, sj.Resource.RESOURCEID);

    repository.Save();
    return RedirectToAction("Index");

和以下视图模型类:-

public class ServerJoin
{
    public TMSServer Server { get; set; }
    public Resource Resource { get; set; }
    public Technology Technology { get; set; }
    public ComponentDefinition ComponentDefinition { get; set; }
}

但是每当我想编辑一个对象时,模型状态将为 False,并且错误消息表明 ILOP 字段是必需的,尽管视图上有它的值?

那么是什么导致了这个问题呢?

更新

模型类是:-

[MetadataType(typeof(TMSServer_Validation))]     
public partial class TMSServer
        {
            public TMSServer()
            {
                this.TMSServers1 = new HashSet<TMSServer>();
                this.TMSVirtualMachines = new HashSet<TMSVirtualMachine>();
            }

            public int ServerID { get; set; }
            public Nullable<int> ServerModelID { get; set; }
            public int DataCenterID { get; set; }
            public string ILOIP { get; set; }
            public int RackID { get; set; }
            public Nullable<int> StatusID { get; set; }
            public Nullable<int> BackUpStatusID { get; set; }
            public int RoleID { get; set; }
            public Nullable<int> OperatingSystemID { get; set; }
            public Nullable<int> VirtualCenterID { get; set; }
            public string Comment { get; set; }
            public byte[] timestamp { get; set; }
            public long IT360SiteID { get; set; }

            public virtual DataCenter DataCenter { get; set; }
            public virtual OperatingSystem OperatingSystem { get; set; }
            public virtual ServerModel ServerModel { get; set; }
            public virtual Technology Technology { get; set; }
            public virtual TechnologyBackUpStatu TechnologyBackUpStatu { get; set; }
            public virtual TechnologyRole TechnologyRole { get; set; }
            public virtual TechnologyStatu TechnologyStatu { get; set; }
            public virtual TMSRack TMSRack { get; set; }
            public virtual ICollection<TMSServer> TMSServers1 { get; set; }
            public virtual TMSServer TMSServer1 { get; set; }
            public virtual ICollection<TMSVirtualMachine> TMSVirtualMachines { get; set; }
        }
4

0 回答 0