I want to scaffold a basic insert form which has dropdowns for the foreign keys.
I cant seem to figure out how to do this. When creating the metadata all the MetaColumns are of type MetaColumns, and none of type MetaForeignKeyColumns - which means that it renders textboxes for all properties - and no dropdown lists.
UIHints seem ineffective. I am using entity framework code first. How do I go about making those textboxes into dropdowns? In fact, I think the MetaData property is not being created ( I am probably missing something here ).
AddPermission.aspx (form only)
<asp:FormView runat="server" ID="AddPermissionForm"
ItemType="Common.Models.tag_permission"
InsertMethod="AddPermissionsForm_InsertItem" DefaultMode="Insert"
RenderOuterTable="false" OnItemInserted="AddPermissionForm_ItemInserted">
<InsertItemTemplate>
<fieldset>
<ol>
<asp:DynamicEntity runat="server" Mode="Insert" EnableViewState="true" ></asp:DynamicEntity>
</ol>
<asp:Button class="btn btn-primary" runat="server" Text="Insert" CommandName="Insert" />
<asp:Button class="btn btn-default" runat="server" Text="Cancel" CausesValidation="false" OnClick="CancelButton_Click" />
</fieldset>
</InsertItemTemplate>
tag_permission.cs ( part of code first model )
public partial class tag_permission
{
[ScaffoldColumn(false)]
public short tp_tag_permission_id { get; set; }
//foreign key one
public string tp_security_group_id { get; set; }
//foreign key two
public short tp_tag_id { get; set; }
[Display(Name = "View")]
public Nullable<bool> tp_vis { get; set; }
}
I might have to use a DynamicDataManager or something, but I'm not sure where to find how or if it should be used on this page alongside the formview.
I've also attached screenshots comparing the rendering of Default_Insert.aspx.cs in my web app, and a basic DynamicData website - almost out of the box from template. In the below pictures, the MetaTable Table property is being inspected in DynamicData/Default_Insert.ascx.cs.
The later image has an incomplete MetaTable property. It has null values for the DataContextType and DataContextPropertyName, and ForeignKeyColumnNames. I'd really like to set the MetaTable on the FormView properly
For reference: The code from the images below is
public partial class Default_InsertEntityTemplate : System.Web.DynamicData.EntityTemplateUserControl {
private MetaColumn currentColumn;
protected override void OnLoad(EventArgs e) {
foreach (MetaColumn column in Table.GetScaffoldColumns(Mode, ContainerType)) {
currentColumn = column;
Control item = new DefaultEntityTemplate._NamingContainer();
EntityTemplate1.ItemTemplate.InstantiateIn(item);
EntityTemplate1.Controls.Add(item);
}
}
...


Theres a few parts to this one:
On startup, I registered the dynamic data provider in global.asax
Global.asax.cs / other
App.cs ( a static class I use to store permanent references )
then on the page where I want to get the meta data I can do this
and then set the metadata
and then the form will render will all foreign keys / navigation properties as they would in a dynamic data website.
All the properties of the ModelMetadata are then set and populated as you would expect - eg with the DataContext and ForeignKeyName are no longer null