我的剃鬚刀視圖中可以不需要字段嗎?MVC4中不需要的字段
我有下面的看法,其中我希望隱藏的字段不是必填字段。 目前它被視爲強制性的,並且我的模型狀態爲false。
請問adivse?
@using P.M.O
@model O
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Create a New O</legend>
<div class="editor-label">
@Html.LabelFor(model => model.C)
@Html.TextBoxFor(model => model.C, new { @class = "txt"})
@Html.ValidationMessageFor(model => model.Caption)
</div> <br />
<div class="editor-label">
@Html.LabelFor(model => model.N)
@Html.TextBoxFor(model => model.N, new { @class = "txt"})
@Html.ValidationMessageFor(model => model.N)
</div> <br />
<div class="editor-label">
@Html.LabelFor(model => model.D)
@Html.TextBoxFor(model => model.D, new { @class = "txt"})
@Html.ValidationMessageFor(model => model.D)
</div>
<br />
@Html.HiddenFor(model=> model.P.Cr)
<input type="submit" value="Create" />
</fieldset>
}
型號:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace P.M.O
{
[Serializable]
public partial class O
{
/*** Construtor(s) ***/
public O()
{
}
public O(P obj)
: this()
{
P= obj;
}
/*** Public Members ***/
[Key, Display(Name = "Id")]
public int PartyId { get; set; }
/* IEntity */
public string C{ get; set; }
public string N{ get; set; }
public string D{ get; set; }
/* IAuditable */
[NotMapped, ScaffoldColumn(false)]
public System.DateTimeOffset Created
{
get { return P.C; }
set { P.C= value; }
}
/* Navigation Properties */
/// <summary>
/// Foreign key to Party: PartyId
/// Organization is subtype of Party
/// </summary>
public virtual P P{ get; set; }
}
}
請發佈您的模型。 –
發佈了模型類..thanku – mmssaann
我假設'model.Party.Created'字段是'DateTime'字段。如果你不想要它,你應該聲明它爲可空的DateTime字段:'public DateTime?創建{get;組; }' –