I have a popup window to be used for editing detailed information of a row in a grid. The popup window's content is from a partial view. In this popup window I have a dropdownlist for states. This custom popup edit window is opened when a custom command button is clicked. I call an action on the controller to pull the data to populate the custom popup, I put that data in a model and I have the custom popup using the model. Everything works fine, except the dropdownlist's selected value is not set. It just shows the first item in the list. I've tried setting the .Value option to the model value - .Value(Model.state) - doesn't work. I've tried using the DataBound event to set the value there to the model.State, but I get errors. If I try to declare the event function in the popup partial view, it doesn't get recognized and I get the not declared error. If I try to declare it in the calling view, it doesn't recognize the model (since it's in the partial view). What am I doing wrong? Any help is very much appreciated!
Thanks!
Donna
Here's the code:
Calling view (Index.cshtml) - grid and popup window:
@model IEnumerable<
GMCEventRegistrationTools.Models.EventRegistrationModel
>
@(Html.Kendo().Grid<
GMCEventRegistrationTools.Models.EventRegistrationModel
>()
.Name("EventRegistrationGrid")
.AutoBind(false)
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.RegistrationKey))
.Read(read => read.Action("Registrants_Read", "Home").Data("registrantsForEvent"))
.Create(update => update.Action("EditingPopup_Create", "Home"))
.Update(update => update.Action("EditingPopup_Update", "Home"))
.Destroy(update => update.Action("EditingPopup_Destroy", "Home"))
)
.Columns(cols =>
{
cols.Bound(p => p.RegistrationKey).Hidden(true);
cols.Bound(p => p.FirstName);
cols.Bound(p => p.LastName);
cols.Bound(p => p.CompanyName);
cols.Bound(p => p.ProvideAccomodations);
cols.Bound(p => p.RegistrationConfirmed);
cols.Command(command => { command.Edit(); command.Destroy(); });
cols.Command(command => command.Custom("Edit Details").Click("editDetails"));
}
)
.ClientDetailTemplateId("registration-client-template")
)
@(Html.Kendo().Window().Name("EditRegDetails")
.Title("Edit Registration")
.Visible(false)
.Modal(true)
.Draggable(true)
.Width(900)
)
function editDetails(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var window = $("#EditRegDetails").data("kendoWindow");
window.refresh({
url: '/Home/GetRegistrationDetails',
data: { id: dataItem.RegistrationKey }
});
window.center();
window.open();
}
Controller/Action:
public ActionResult GetRegistrationDetails(int id)
{
EventRegistrationModel eRegistrationModel = new EventRegistrationModel();
using (var eventTools = new WebDBEntities())
{
WebEventRegistration reg = eventTools.WebEventRegistrations.Where(p => p.RegistrationKey == id).FirstOrDefault();
AdditionalInfo ai = new AdditionalInfo();
var serializer = new JavaScriptSerializer();
if (reg != null && (reg.FirstName != null && reg.FirstName != ""))
{
eRegistrationModel.AddressLine1 = reg.AddressLine1;
eRegistrationModel.AddressLine2 = reg.AddressLine2;
eRegistrationModel.City = reg.City;
eRegistrationModel.CompanyName = reg.CompanyName;
eRegistrationModel.EmailAddress = reg.EmailAddress;
eRegistrationModel.EventDetails = serializer.Deserialize<
AdditionalInfo
>(reg.EventDetails);
eRegistrationModel.EventName = reg.EventName;
eRegistrationModel.FirstName = reg.FirstName;
eRegistrationModel.JobTitle = reg.JobTitle;
eRegistrationModel.LastName = reg.LastName;
eRegistrationModel.MiddileInitial = reg.MiddileInitial;
eRegistrationModel.PhoneNumber = reg.PhoneNumber;
eRegistrationModel.PostalCode = reg.PostalCode;
eRegistrationModel.ProvideAccomodations = reg.ProvideAccomodations == 0 ? true : false;
eRegistrationModel.ReferrerIpAddress = reg.ReferrerIpAddress;
eRegistrationModel.RegistrationConfirmed = reg.RegistrationConfirmed == 0 ? true : false;
eRegistrationModel.RegistrationDate = reg.RegistrationDate;
eRegistrationModel.State = reg.State;
eRegistrationModel.RegistrationKey = reg.RegistrationKey;
}
else
{
return View("Error");
}
}
return PartialView("EditRegistrationDetails", eRegistrationModel);
}
Partial view with dropdown:
@model GMCEventRegistrationTools.Models.EventRegistrationModel
@using (Html.BeginForm("SaveRegistrationEdit", "Home", FormMethod.Post, new { id = "editregis-form" }))
{
most fields removed for brevity
<
div
class
=
"form-group"
>
@Html.LabelFor(model => model.State)
@(Html.Kendo().DropDownListFor(model => model.State).Name("State")
.HtmlAttributes(new { @class = "form-control textbox-size stateslist"})
.DataTextField("State").DataValueField("StateCode")
.DataSource(source => {
source.Read(read =>
{
read.Action("GetStates", "Home");
});
})
.Value(Model.State)
.Events(events => events.DataBound("setSelectedState"))
)
<
p
class
=
"error"
>@Html.ValidationMessageFor(model => model.State)</
p
>
</
div
>
Thanks!
Donna