I have a Supplier Entitiy that contains
ID - int
Status - string
Name - string
CreateDate- datetime
I am using the partial class method to create Data Annotations for the above Entity.as described here
namespace TemplateEx.Models
{
[MetadataType(typeof(SupplierMetadata))]
public partial class Supplier
{
// Note this class has nothing in it. It's just here to add the class-level attribute.
}
public class SupplierMetadata
{
// Name the field the same as EF named the property - "FirstName" for example.
// Also, the type needs to match. Basically just redeclare it.
// Note that this is a field. I think it can be a property too, but fields definitely should work.
[Required]
[Display(Name = "Supplier Name")]
public string Name;
}
}
My defined a controller action as below
public ViewResult Details(int id)
{
Supplier supplier = db.Suppliers1.Single(s => s.ID == id);
return View(supplier);
}
When I create a view for this action and picked the Details scaffolding for the Supplier entity following is what I got as a view
@model TemplateEx.Models.Supplier
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
<fieldset>
<legend>Supplier</legend>
<div class="display-label">CreateDate</div>
<div class="display-field">
@Html.DisplayFor(model => model.CreateDate)
</div>
<div class="display-label">Status</div>
<div class="display-field">
@Html.DisplayFor(model => model.Status)
</div>
<div class="display-label">Name</div>
<div class="display-field">
@Html.DisplayFor(model => model.Name)
</div>
</fieldset>
<p>
@Html.ActionLink("Edit", "Edit", new { id=Model.ID }) |
@Html.ActionLink("Back to List", "Index")
</p>
Notice how the model.Name has a “Name” label instead of “Supplier Name”.What am I doing wrong?
replace
with
Edit :
For the second question, look here
How can i enforce the scaffolding automatically generated code to display the Label and the EditorFor text field at the same line in my asp.net mvc 3 (specially last answer)