I have a page with two DatePickers where i select a start date and a end date. When the button named "Submit" is pressed the partial view should be loaded ,but i get the error "Google is not defined", Here is the code for in the parent view which load the partial view :
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<script>
$(function () {
$("#txtdatepicker1").datepicker();
$("#txtdatepicker2").datepicker();
});
function CalendarClick() {
$("#divul").load("/Greenhouse/Calendarul?startDate=" + $("#txtdatepicker1").val() + "&endDate=" + $("#txtdatepicker2").val());
}
</script>
<h2>
Datepicker Calender
</h2>
@using (Html.BeginForm())
{
<table>
<tr>
<td>
<p>
Start Date: @Html.TextBoxFor(m => m.StartDate, new { @id = "txtdatepicker1", @style = "width:200px;" })
</p>
</td>
<td>
<p>
End Date: @Html.TextBoxFor(m => m.EndDate, new { @id = "txtdatepicker2", @style = "width:200px;" })
</p>
</td>
</tr>
</table>
<input type="button" name="btnSubmit" value="Submit" onclick="CalendarClick()"/>
<div id="divul"></div>
}
And here is the partial view, but the function is never called :
@model Plotting.Models.ChartDate
@{
ViewBag.Title = "How To Create Dynamic Google Column Chart In an Asp.Net MVC Application Using C# ";
}
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
alert("aaa");
// Create and populate the data table.
var days = [@Model.DateData.Date];
var humidities1 = [@Model.DateData.Humidity1];
var humidities2 = [@Model.DateData.Humidity2];
var data = new google.visualization.DataTable();
data.addColumn('string', '@Model.DateTitle');
data.addColumn('number', '@Model.HumidityTitle1');
data.addColumn('number', '@Model.HumidityTitlle2');
for (i = 0; i < days.length; i++) {
data.addRow([days[i].toString(), humidities1[i], humidities2[i]]);
}
var options = {
title: 'Humidities Values',
hAxis: { title: '@Model.DateTitle', titleTextStyle: { color: 'black' } }
};
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
<fieldset>
<legend><strong>Greenhouse</strong></legend>
<div id="chart_div" style="width: auto; height: auto;">
</div>
</fieldset>
Thank you!