The partial class:
using System.ComponentModel.DataAnnotations;
namespace CSR.Models
{
[MetadataType(typeof(SO_Validation))]
public partial class SO
{
//__
}
public class SO_Validation
{
[ScaffoldColumn(false)]
public Int16 soID { get; set; }
[Display(Name = "Full Name")]
[Required(ErrorMessage = "Name is required.")]
[StringLength(50, ErrorMessage = "Name cannot have more than 50 characters.")]
public string Name { get; set; }
// more columns follow.
}
}
In the Controller:
namespace CSR.Controllers
{
[Authorize]
public class UpdateController : Controller
{
SoRepository soRepository = new SoRepository();
public ActionResult AddSO()
{
SO so = new SO();
return View(so);
}
}
Shouldn't ScaffoldColumn(false) hide the field in the view?
I create a strongly typed CREATE view (AddSO), expecting that the soID column won't be rendered and that the Label name of the field 'name' will be 'Full Name'. But the view renders the soID column and still labels the 'Name' field as 'Name.
What am I doing wrong?
Update: After using the Html.EditorForModel() helper method, ScaffoldColumn(false) now works and hides the soID field (Yeah! ... wonder why VS doesn't use that by default when generating the view?):
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Please enter the following details:</legend>
<%= Html.EditorForModel() %>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
However the [Display(Name = "Full Name")] attribute (which is supposed to update the label name to "Full Name") still doesn't work.