Hi,
I'm trying to have my ListView bind to a model item, so that when postback occurs, the entries updated to the listview, are reflected in the associated model field.When I attempt this with the below code though, I receive a NullReferenceException from the view code that I've posted below. I've included the model also, as well as the stack trace. Any help with this one is greatly appreciated! Thanks!
Model:
public
class
CustomerCreateModel
{
#region private fields
private
ICollection<CreateSecurityQuestionModel> _SecurityQuestions =
new
List<CreateSecurityQuestionModel>();
#endregion
[Required(AllowEmptyStrings =
false
), Display(Name =
"First Name"
)]
public
string
FirstName {
get
;
set
; }
[Required(AllowEmptyStrings =
false
), Display(Name =
"Last Name"
)]
public
string
LastName {
get
;
set
; }
public
ICollection<SecurityQuestionModel> SecurityQuestions
{
get
{
return
_SecurityQuestions; }
set
{ _SecurityQuestions = value; }
}
}
View Code:
@model CustomerCreateModel
<
div
class
=
"form-group"
>
@Html.Label("Security Questions", htmlAttributes: new { @class = "control-label col-md-2" })
<
div
class
=
"col-md-10"
>
<
div
style
=
"clear: both;"
>
<
a
class
=
"k-button k-button-icontext k-add-button"
href
=
"#"
><
span
class
=
"k-icon k-add"
></
span
>Add new security question</
a
>
@(Html.Kendo().ListView<
SecurityQuestionModel
>(Model.SecurityQuestions)
.Name("SecurityQuestionsListView")
.TagName("div")
.ClientTemplateId("security-qa-template")
.DataSource(dataSource => dataSource
.Model(model => model.Id("Id"))
.PageSize(10)
.Create(create => create.Action("Create", "Customers"))
.Update(update => update.Action("Update", "Customers"))
)
.Pageable()
.Editable(e => e.TemplateName("QuestionAnswerEditor"))
)
</
div
>
</
div
>
</
div
>