I am creating an MVC 5 app in VS 2013.
I have a master view that calls a partial view for a model. That partial view has several controls related to a "relationship", including a button for the user to click to create a record for a new organization with which we have a relationship in case that organization does not yet exist in our records.
When the user clicks the button, a Kendo modal window (partial view) pops up and display controls for the user to fill in for the new organization. One of those controls is a Razor @Html.DropDownListFor() which displays the cities and counties.
So far, so good.
The "city" dropdown (Razor @Html) has text in the pattern City;County. When the user selects a City/County, I want to put the city value into the city box (the same select, for now, but it could be a different control) and the county name into the the CountyName textbox.
The code for the DropDownList/(HTML Select) is
@Html.DropDownListFor(model => model.City, @CityCountySelectList, new
{
htmlAttributes = new
{
@class = "form-control",
title = "Select city and county simultaneously",
onchange = "javascript:GetStringElement(value, 0, ';')"
}
})
But the javascript is never called (based on my step-through debugging in Chrome). I have tried the JavaScript call with and without "javascript:" and put the GetStringElement function in various places to no avail:
1. @scripts on the main and calling view
2. <script> on the main and calling view
3. in the document.ready function for the modal window.
4. On a separate javascript file.
5. Inline in the onchange event.
The code to call the modal is:
<div id="KendoOrgModal">
<p>Don't see your organization in the list? <span id="new_org_btn" class="k-button">Add a new one</span></p>
@*re: modal window scrolling against main window: http://www.telerik.com/forums/kendo-ui-window-disable-background-scrolling *@
@(Html.Kendo().Window()
.Name("new_org_window")
@* CSS width determines total display width for controls *@
.HtmlAttributes(new { style = "width:64em; overflow:hidden;" })
.Title("New Organization")
.Content("loading form...")
.LoadContentFrom("_Create", "Org")
.Iframe(false)
.Draggable()
.Visible(false)
.Resizable(opts => opts.Enabled(false))
.Height(875)
@* width property determines width of popup modal window *@
.Width(890)
.Scrollable(false)
.Events(events => events
.Close("on_org_window_close")
)
)
<script>
function on_org_window_close(e)
{
var org_cmb = $("#EditModel_CRAOrgID").data("kendoComboBox")
org_cmb.dataSource.read();
org_cmb.refresh();
}
$(document).ready(function() {
$("#new_org_btn")
.bind("click", function() {
$("#new_org_window").data("kendoWindow").open();
});
});
</script>
</div>
How can I make the DropDownListFor call the JavaScript code?
I have a master view that calls a partial view for a model. That partial view has several controls related to a "relationship", including a button for the user to click to create a record for a new organization with which we have a relationship in case that organization does not yet exist in our records.
When the user clicks the button, a Kendo modal window (partial view) pops up and display controls for the user to fill in for the new organization. One of those controls is a Razor @Html.DropDownListFor() which displays the cities and counties.
So far, so good.
The "city" dropdown (Razor @Html) has text in the pattern City;County. When the user selects a City/County, I want to put the city value into the city box (the same select, for now, but it could be a different control) and the county name into the the CountyName textbox.
The code for the DropDownList/(HTML Select) is
@Html.DropDownListFor(model => model.City, @CityCountySelectList, new
{
htmlAttributes = new
{
@class = "form-control",
title = "Select city and county simultaneously",
onchange = "javascript:GetStringElement(value, 0, ';')"
}
})
But the javascript is never called (based on my step-through debugging in Chrome). I have tried the JavaScript call with and without "javascript:" and put the GetStringElement function in various places to no avail:
1. @scripts on the main and calling view
2. <script> on the main and calling view
3. in the document.ready function for the modal window.
4. On a separate javascript file.
5. Inline in the onchange event.
The code to call the modal is:
<div id="KendoOrgModal">
<p>Don't see your organization in the list? <span id="new_org_btn" class="k-button">Add a new one</span></p>
@*re: modal window scrolling against main window: http://www.telerik.com/forums/kendo-ui-window-disable-background-scrolling *@
@(Html.Kendo().Window()
.Name("new_org_window")
@* CSS width determines total display width for controls *@
.HtmlAttributes(new { style = "width:64em; overflow:hidden;" })
.Title("New Organization")
.Content("loading form...")
.LoadContentFrom("_Create", "Org")
.Iframe(false)
.Draggable()
.Visible(false)
.Resizable(opts => opts.Enabled(false))
.Height(875)
@* width property determines width of popup modal window *@
.Width(890)
.Scrollable(false)
.Events(events => events
.Close("on_org_window_close")
)
)
<script>
function on_org_window_close(e)
{
var org_cmb = $("#EditModel_CRAOrgID").data("kendoComboBox")
org_cmb.dataSource.read();
org_cmb.refresh();
}
$(document).ready(function() {
$("#new_org_btn")
.bind("click", function() {
$("#new_org_window").data("kendoWindow").open();
});
});
</script>
</div>
How can I make the DropDownListFor call the JavaScript code?