I am trying to use metadata to further define my entity objects using MVC2, LINQ to SQL, and VB.NET. Here are the two main pieces of code in question:
<HiddenInput(DisplayValue:=False)> _
<Column(IsPrimaryKey:=True, IsDbGenerated:=True, AutoSync:=AutoSync.OnInsert)> _
Public Property ItemID As Integer
Get
Return _itemID
End Get
Set(value As Integer)
_itemID = value
End Set
End Property
<DataType(DataType.MultilineText)> _
<Column()> _
Public Property Description As String
Get
Return _description
End Get
Set(value As String)
_description = value
End Set
End Property
Here’s the code for my view:
<div class="editor-label">
<%: Html.LabelFor(Function(model) model.ItemID) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(Function(model) model.ItemID) %>
<%: Html.ValidationMessageFor(Function(model) model.ItemID) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(Function(model) model.Description) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(Function(model) model.Description) %>
<%: Html.ValidationMessageFor(Function(model) model.Description) %>
</div>
For the first example, my Create View is supposed to render the input tag ‘hidden’ in the resulting html. In the second example, my Create View is supposed to render a larger input text field for description, because of the metadata and the metadata, respectively. However, neither occurs.
The first thing that comes to mine is that maybe I am defining metadata in VB.NET syntactically inappropriately. All of my examples of defining metadata are in C#… I can find absolutely zero examples in VB.NET. Please help.
Html.TextBoxFor()always renders a visible text box. Hence the name. 🙂To have a different kind of editor based on the attributes, use
Html.EditorFor()instead.