So in case anyone come across this and wants to know how I solved it, it was indeed a question of creating a foreign key. I changed my Properties list to include an auto-incrementing ID as well as the Name, and built the foreign key against the list of properties. Actually, it worked quite well. I still have to figure out how to remove a used property from the dropdown, but one problem at a a time.
I'll include the new class definitions as well as what I have in the ASPX page...
namespace
FileUploader_Mapper.Models
{
public
class
CSVColumn
{
public
int
ColumnNumber {
get
;
set
; }
public
string
ColumnName {
get
;
set
; }
public
int
MappedTo {
get
;
set
; }
}
public
class
MappingProperty
{
private
static
int
counter;
public
int
Id {
get
;
private
set
; }
public
string
Name {
get
;
private
set
; }
public
MappingProperty(
string
propertyName)
{
Id = ++counter;
Name = propertyName;
}
}
public
class
CSVColumnsViewModel
{
public
string
CSVFile {
get
;
set
; }
public
List<CSVColumn> Columns =
new
List<CSVColumn>();
public
List<MappingProperty> MappingProperties {
get
;
set
; }
public
CSVColumnsViewModel()
{
MappingProperties =
new
List<MappingProperty>
{
new
MappingProperty(
"SSN"
),
new
MappingProperty(
"FirstName"
),
new
MappingProperty(
"LastName"
),
new
MappingProperty(
"Address1"
),
new
MappingProperty(
"Address2"
),
new
MappingProperty(
"City"
),
new
MappingProperty(
"State"
),
new
MappingProperty(
"Zip"
)
};
}
}
}
@
using
FileUploader_Mapper.Models
@model CSVColumnsViewModel
@{
ViewBag.Title =
"Result"
;
}
<style>
.k-grid td {
line-height: 2em;
padding: 0 0 0 1em;
}
</style>
<h2>Result</h2>
<p></p>
@(Html.Label(
"lblMisc"
,
"Columns from CSV File: "
+ Model.CSVFile))<br/>
@(Html.Kendo().Grid(Model.Columns)
.Name(
"csvGrid"
)
.HtmlAttributes(
new
{ style =
"width: 650px"
})
.Columns(col =>
{
col.Bound(c => c.ColumnNumber).Width(125).Title(
"Column Number"
);
col.Bound(c => c.ColumnName).Title(
"Column Name"
);
col.ForeignKey(c => c.MappedTo, Model.MappingProperties,
"Id"
,
"Name"
).Title(
"Mapped To"
);
})
.ToolBar(toolBar =>
{
toolBar.Create();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.DataSource(ds => ds
.Ajax()
.PageSize(20)
.ServerOperation(
false
)
.Model(m =>
{
m.Id(c => c.ColumnNumber);
m.Field(c => c.ColumnName).Editable(
false
);
m.Field(c => c.MappedTo).DefaultValue(0);
})
)
.Pageable()
)