title: C# MVC controller called twice
body: <p>I am making a C# Razor MVC web app that is geared for Ipad. I am using JQuery mobile and Kendo UI. I have 2 input forms that use the Kendo grid that sit in a JQuery popup window.</p>
  
  <p>My problem is that the Waste_Read controller is double firing and makes 2 kendo grids. This is unnoticeable in desktop apps but on the ipad 2 grids are visible.</p>
  
  <p>Below is my _Layout.cshtml and Ham.cshtml (which is my view) code.</p>
  
  <p>Thanks!</p>
  
  <p><strong>_Layout.cshtml</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  @{
  
  if (Session["currentDate"] == null)
  {
  HttpContext.Current.Session["currentDate"] = DateTime.Today.ToString("yyyy-MM-dd");
  }
  
  if (Session["currentShift"] == null)
  {
  HttpContext.Current.Session["currentShift"] = 1;
  }
  
  if (Session["ReportType"] == null)
  {
  HttpContext.Current.Session["ReportType"] = "Daily";
  }
  
  }
  
  &lt;title&gt;@ViewBag.Title&lt;/title&gt;
  &lt;meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width=device-width" /&gt;
  &lt;meta name="apple-mobile-web-app-capable" content="yes" /&gt;
  &lt;link href="~/Resources/Triangle.ico" rel="shortcut icon" type="image/x-icon" /&gt;
  
  @Styles.Render("~/Content/mobileCss", "~/Content/css")
  @Scripts.Render("~/bundles/modernizr")
  @Scripts.Render("~/bundles/jquery", "~/bundles/jquerymobile")
  
  &lt;link href="@Url.Content("~/Content/kendo/2013.1.319/kendo.common.min.css")" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="@Url.Content("~/Content/kendo/2013.1.319/kendo.dataviz.min.css")" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="@Url.Content("~/Content/kendo/2013.1.319/kendo.silver.min.css")" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="@Url.Content("~/Content/kendo/2013.1.319/kendo.dataviz.silver.min.css")" rel="stylesheet" type="text/css" /&gt;
  
  @*&lt;script src="@Url.Content("~/Scripts/kendo/2013.1.319/jquery.min.js")"&gt;&lt;/script&gt;*@
  &lt;script src="@Url.Content("~/Scripts/kendo/2013.1.319/kendo.all.min.js")"&gt;&lt;/script&gt;
  &lt;script src="@Url.Content("~/Scripts/kendo/2013.1.319/kendo.aspnetmvc.min.js")"&gt;&lt;/script&gt;
  @*&lt;script src="@Url.Content("~/Scripts/kendo.modernizr.custom.js")"&gt;&lt;/script&gt;*@
  &lt;script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
  
  
  //prevents ipad vertical bounce scrolling
  document.ontouchmove = function (event) {
  event.preventDefault();
  }
  
  function UpdateDate() {
  UpdateSessionDate();
  UpdateSessionShift();
  UpdateSessionReportType();
  
  //$('#datepick').val('AT(Session["currentDate"])');
  
  var DatePageType = '@(ViewBag.DatePageType)';
  
  if (DatePageType == "Reporting") {
  
  UpdateCharts();
  }
  if (DatePageType == "LiveView") {
  UpdateViews($('#hoursaver').val());
  UpdateLineViews($('#hoursaver').val());
  UpdateOverallInfoBox($('#linesaver').val());
  UpdateOverviewOfLabourChart()
  }
  if (DatePageType == "LabourEntry") {
  // UpdateViews($('#hoursaver').val());
  refreshLabourEntry();
  }
  
  }
  
  function UpdateShift() {
  UpdateSessionDate();
  UpdateSessionShift();
  
  //$('#datepick').val('AT(Session["currentDate"])');
  
  var DatePageType = '@(ViewBag.DatePageType)';
  
  if (DatePageType == "Reporting") {
  UpdateCharts();
  }
  if (DatePageType == "LiveView") {
  UpdateViews($('#hoursaver').val());
  UpdateLineViews($('#hoursaver').val());
  UpdateOverallInfoBox($('#linesaver').val());
  }
  if (DatePageType == "LabourEntry") {
  refreshLabourEntry();
  
  }
  }
  
  function pullfrompeviousLoad(objThis) {
  var url = $(objThis).data('url') + '?hour=' + $(objThis).data('hour') + '&amp;Shift=' + $(objThis).data('shift') + '&amp;LineName=' + $(objThis).data('line');
  window.location.href = url;
  }
  
  function menuLoad(objThis) {
  var url = $(objThis).data('url');
  window.location.href = url;
  }
  
  function buttonLoad(objThis) {
  var url = $(objThis).data('url') + '?hour=' + $(objThis).data('time');
  window.location.href = url;
  }
  
  function saveLoad(objThis) {
  
  $('#labourform').submit();
  var url = $(objThis).data('url') + '?hour=' + $(objThis).data('time');
  window.location.href = url;
  return false;
  }
  
  // update date session data
  function UpdateSessionDate() {
  
  $.post('/SetSession/SetVariable',
  {
  key: "currentDate",
  value: kendo.toString($("#datepicker").data("kendoDatePicker").value(), "yyyy-MM-dd")
  });
  
  };
  
  // update shift session data
  function UpdateSessionShift() {
  
  $.post('/SetSession/SetVariable',
  {
  key: "currentShift",
  value: $('#shift').val()
  });
  
  };
  
  
  // update report type session data
  function UpdateSessionReportType() {
  
  $.post('/SetSession/SetVariable',
  {
  key: "ReportType",
  value: $('#ReportType').val()
  });
  
  };
  
  function UpdateButtons(h) {
  var arrayToModify = [];
  var i = 0, j, k, buttonsToCreate, buttonContainer, newButton;
  var buttonsToCreate = [];
  var now = parseInt(h);
  
  for (var j = (now - 7) ; j &lt;= (now + 7) ; j++) {
  
  if (j &gt;= 0 &amp;&amp; j &lt;= 23) {
  buttonsToCreate[i] = j;
  i++;
  }
  }
  
  buttonContainer = document.getElementById('ddShift');
  
  for (k = 0; k &lt; buttonsToCreate.length; k++) {
  
  if (buttonsToCreate[k] == parseInt(h) + 1) {
  newButton.style.cssText = 'background-color: red;';
  }
  
  newButton = document.createElement('input');
  newButton.type = 'button';
  newButton.value = buttonsToCreate[k];
  newButton.id = buttonsToCreate[k];
  newButton.onclick = function () {
  arrayToModify[arrayToModify.length] = this.id;
  $('#hoursaver').val(this.id);
  UpdateViews(this.id);
  UpdateLineViews(this.id);
  };
  
  buttonContainer.appendChild(newButton);
  }
  };
  
  kendo.culture("en-US");
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;div data-role="page" data-theme="b" id="index"&gt;
  
  &lt;div data-role="header" data-position="fixed"&gt;
  &lt;h1&gt;@ViewBag.Title&lt;/h1&gt;
  &lt;a href="#nav-panel" data-icon="bars" data-iconpos="notext" class="ui-btn-left"&gt;Menu&lt;/a&gt;
  
  @if (Request.IsAuthenticated)
  {
  @Html.ActionLink("My Account", "Index", "Account", routeValues: null, htmlAttributes: new { data_icon = "gear" })
  }
  else
  {
  @Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { data_icon = "gear" })
  }
  
  
  &lt;div class="datepickerbtn" style="width: 212.5px;"&gt;
  
  @(Html.Kendo().DatePicker()
  .Name("datepicker")
  .Events(e =&gt;
  {
  e.Change("UpdateDate");
  })
  .Format("yyyy-MM-dd")
  .Value((String)Session["currentDate"])
  )
  &lt;/div&gt;
  
  &lt;div class="shiftpickerbtn" id="btnshift"&gt;
  &lt;select id="shift" name="shift" onchange="UpdateShift()"&gt;
  &lt;option value="1"&gt;Shift 1&lt;/option&gt;
  &lt;option value="2"&gt;Shift 2&lt;/option&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  
  
  &lt;/div&gt;
  &lt;div data-role="content"&gt;
  
  @RenderBody()
  &lt;/div&gt;
  &lt;div data-role="footer" style="text-align: center" data-position="fixed"&gt;
  @RenderSection("footer", false)
  &lt;/div&gt;
  &lt;div data-role="panel" data-position-fixed="true" data-theme="b" data-content-theme="d" id="nav-panel"&gt;
  &lt;ul data-role="listview" data-theme="a" class="nav-search"&gt;
  &lt;li data-icon="delete"&gt;&lt;a href="#" data-rel="close"&gt;Close menu&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a data-url="@Url.Action("Index", "Home")" onclick="menuLoad(this)"&gt;Home&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a data-url="@Url.Action("Index", "LabourEntry")" onclick="menuLoad(this)"&gt;Labour Entry&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a data-url="@Url.Action("Index", "LiveView")" onclick="menuLoad(this)"&gt;Live View&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a data-url="@Url.Action("Index", "Report")" onclick="menuLoad(this)"&gt;Reporting&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a data-url="@Url.Action("Loin", "ScheduleBuilder")" onclick="menuLoad(this)"&gt;Schedule Builder&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a data-url="@Url.Action("About", "Home")" onclick="menuLoad(this)"&gt;About&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a data-url="@Url.Action("Contact", "Home")" onclick="menuLoad(this)"&gt;Contact&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  
  &lt;/div&gt;
  
  &lt;/div&gt;
  
  @RenderSection("scripts", required: false)
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Ham.cshtml</strong></p>
  
  <pre><code>@model IEnumerable&lt;OPS.Models.LabourSchedule&gt;
  
  @{
  ViewBag.Title = "Ham";
  Layout = "~/Views/Shared/_Layout.cshtml";
  ViewBag.DatePageType = "LabourEntry";
  }
  
  &lt;script&gt;
  
  $(document).ready(function () {
  
  //set the value of the datepicker and Shift via session variables
  $('#datepicker').val('@(Session["currentDate"])');
  $('#shift').val('@(Session["currentShift"])');
  $('#shift').selectmenu('refresh');
  
  $('#lblWasteFormDate').html('@(Session["currentDate"])');
  
  });
  
  function Update_Data() {
  return {
  CurDate: kendo.toString($("#datepicker").data("kendoDatePicker").value(), "yyyy-MM-dd")
  };
  }
  
  function Read_Data() {
  return {
  LineName: "Ham",
  CurDate: kendo.toString($("#datepicker").data("kendoDatePicker").value(), "yyyy-MM-dd"),
  ShiftName: @(Session["currentShift"]) + ""
  };
  }
  
  function Read_DT_Data() {
  return {
  LineName: "Ham",
  CurDate: kendo.toString($("#datepicker").data("kendoDatePicker").value(), "yyyy-MM-dd"),
  ShiftName: $("#shift").val() + ""
  };
  }
  
  &lt;/script&gt;
  
  
  @section footer
  {
  &lt;div data-inline="true"&gt;
  
  &lt;div data-inline="true"&gt;
  @if (ViewBag.curHour &gt; 0)
  {                                    
  &lt;a data-role="button" href="#" data-url="@Url.Action("Ham", "LabourEntry")" onclick="buttonLoad(this)"  data-icon="arrow-l" data-iconpos="notext" data-theme="c" data-inline="true" data-time="@ViewBag.prevHour"&gt;&lt;/a&gt;                  
  }
  @for (var i = ViewBag.curHour - 7; i &lt;= ViewBag.curHour + 7; i++)
  {
  
  if (ViewBag.curHour == i)
  {                            
  &lt;a data-role="button" href="#" data-theme="b" data-inline="true"&gt;@i&lt;/a&gt;                                
  }
  else if (@i &gt;= 0 &amp;&amp; @i &lt;= 23)
  {                             
  &lt;a data-role="button" href="#" data-url="@Url.Action("Ham", "LabourEntry")" onclick="buttonLoad(this)" data-theme="c" data-inline="true" data-time="@i"&gt;@i&lt;/a&gt;                                          
  
  }
  
  }
  @if (ViewBag.curHour &lt; 23)
  {                                                          
  &lt;a data-role="button" href="#" data-url="@Url.Action("Ham", "LabourEntry")" onclick="buttonLoad(this)"  data-icon="arrow-r" data-iconpos="notext" data-theme="c" data-inline="true" data-time="@ViewBag.nextHour"&gt;Arrow right&lt;/a&gt;                    
  }
  &lt;a href="#popupMenu" data-rel="popup" data-role="button" data-inline="true" data-transition="slideup" data-icon="grid" data-iconpos="notext" data-theme="b"&gt;Options&lt;/a&gt;
  &lt;/div&gt;
  
  &lt;/div&gt;
  &lt;div data-role="popup" id="popupDownTime" class="ui-content" data-theme="d" data-overlay-theme="a" data-dismissible="false" style="width: 80%; position: relative; margin: 20px auto;"&gt;
  &lt;a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right"&gt;Close&lt;/a&gt;
  
  &lt;div id="update-message"&gt;&lt;/div&gt;
  @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "DTForm" }))
  {
  
  &lt;input type="hidden" name="LineName" value="Ham" /&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td colspan="3"&gt;
  &lt;label for="categories"&gt;Downtime Reason:&lt;/label&gt;
  @(Html.Kendo().DropDownList()
  .Name("DTCatId")
  .OptionLabel("Select downtime...")
  .HtmlAttributes(new { style = "width:90%;" })
  .DataTextField("Name")
  .DataValueField("ID")
  .DataSource(source =&gt;
  {
  source.Read(read =&gt;
  {
  read.Action("GetDowntimeCategories", "LabourEntry");
  });
  })
  )
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;label for="txt_DT_Duration"&gt;Duration (minutes):&lt;/label&gt;
  &lt;input type="number" name="DT_Duration" pattern="[0-9]*" id="txt_DT_Duration" value="" /&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;label for="txt_DT_People"&gt;# of People:&lt;/label&gt;
  &lt;input type="number" name="DT_People" pattern="[0-9]*" id="txt_DT_People" value="" /&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;label for="sl_Hrs_Type"&gt;Hours Type:&lt;/label&gt;
  &lt;select name="Hrs_Type" id="sl_Hrs_Type" data-role="slider"&gt;
  &lt;option value="OT"&gt;OT&lt;/option&gt;
  &lt;option value="REG" selected="selected"&gt;Reg&lt;/option&gt;
  &lt;/select&gt;
  &lt;/td&gt;
  
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td colspan="3"&gt;
  &lt;label for="txt_DT_Desc"&gt;Description Detail:&lt;/label&gt;
  &lt;textarea rows="12" name="DT_Desc" id="txt_DT_Desc"&gt;&lt;/textarea&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td colspan="3"&gt;
  &lt;input type="submit" name="submit" value="Add Downtime" /&gt;
  &lt;/td&gt;
  
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td colspan="3"&gt;
  @(Html.Kendo().Grid&lt;OPS.Models.DownTime&gt;()
  .Name("DTGrid")
  .Columns(columns =&gt;
  {
  columns.Bound(p =&gt; p.ID).Hidden(true);
  columns.Bound(p =&gt; p.DT_ID).Hidden(true);
  columns.Bound(p =&gt; p.HR_TYPE).Hidden(true);
  columns.Bound(p =&gt; p.LINE_ID).Hidden(true);
  columns.Bound(p =&gt; p.SHIFT).Hidden(true);
  columns.Bound(p =&gt; p.USER_ID).Hidden(true);
  columns.Bound(p =&gt; p.DT_REASON).Title("Reason");
  columns.Bound(p =&gt; p.DT_DETAIL).Title("Details");
  columns.Bound(p =&gt; p.DURATION).Title("Duration (mins)");
  columns.Bound(p =&gt; p.NUM_EFFECTED).Title("# of People");
  })
  .ToolBar(toolbar =&gt;
  {
  toolbar.Save();
  })
  .Editable(editable =&gt; editable.Mode(GridEditMode.InCell))
  .Sortable()
  .Scrollable()
  .Resizable(resize =&gt; resize.Columns(true))
  .DataSource(dataSource =&gt; dataSource
  .Ajax()
  .Model(model =&gt;
  {
  model.Id(p =&gt; p.ID);
  })
  .Batch(true)
  .ServerOperation(false)
  .Events(events =&gt; events.Error("error"))              
  .Read(read =&gt; read.Action("DT_Read", "LabourEntry")
  .Data("Read_DT_Data"))
  .Update(update =&gt; update.Action("DT_Update", "LabourEntry"))
  )
  )
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  
  }
  &lt;/div&gt;
  
  &lt;div data-role="popup" id="popupWaste" class="ui-content" data-theme="d" data-overlay-theme="a" data-dismissible="false" style="width: 90%; position: relative; margin: 20px auto;"&gt;
  &lt;a href="#" data-rel="back" data-role="button" data-theme="a" data-icon="delete" data-iconpos="notext" class="ui-btn-right"&gt;Close&lt;/a&gt;
  
  &lt;div style="width: 100%;"&gt;
  
  &lt;h3&gt;Date: &lt;label id="lblWasteFormDate"&gt;&lt;/label&gt;
  &lt;/h3&gt;
  
  
  @(Html.Kendo().Grid&lt;OPS.Models.LineProductWasteEntry&gt;()
  .Name("WasteGrid")
  .Columns(columns =&gt;
  {
  
  columns.Bound(p =&gt; p.Id).Hidden(true);
  columns.Bound(p =&gt; p.BucketWeight).Hidden(true);
  columns.Bound(p =&gt; p.LineCategoryId).Hidden(true);
  columns.Bound(p =&gt; p.LineCategoryProduct).Hidden(true);
  columns.Bound(p =&gt; p.LineProductId).Hidden(true);
  columns.Bound(p =&gt; p.ShiftId).Hidden(true);
  columns.Bound(p =&gt; p.SourceId).Hidden(true);
  columns.Bound(p =&gt; p.UserId).Hidden(true);
  columns.Bound(p =&gt; p.CategoryName);
  columns.Bound(p =&gt; p.ProductName);
  columns.Bound(p =&gt; p.Value);
  columns.Bound(p =&gt; p.SourceName);
  columns.Bound(p =&gt; p.Source);
  columns.Bound(p =&gt; p.Weight);
  columns.Bound(p =&gt; p.Weight2);
  columns.Bound(p =&gt; p.Weight3);
  })
  .ToolBar(toolbar =&gt;
  {
  toolbar.Save();
  })
  .Editable(editable =&gt; editable.Mode(GridEditMode.InCell))
  .Sortable()
  .Scrollable()
  .Resizable(resize =&gt; resize.Columns(true))
  .DataSource(dataSource =&gt; dataSource
  .Ajax()
  .Model(model =&gt;
  {
  model.Id(p =&gt; p.Id);
  model.Field(p =&gt; p.SourceName).Editable(false);
  model.Field(p =&gt; p.CategoryName).Editable(false);
  model.Field(p =&gt; p.ProductName).Editable(false);
  model.Field(p =&gt; p.Value).Editable(false);
  })
  .Batch(true)
  .ServerOperation(false)
  .Events(events =&gt; events.Error("error"))        
  .Read(read =&gt; read.Action("Waste_Read", "LabourEntry")
  .Data("Read_Data"))
  .Update(update =&gt; update.Action("Waste_Update", "LabourEntry")
  .Data("Update_Data"))
  
  )
  
  )
  
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div data-role="popup" id="popupMenu" data-theme="a"&gt;
  &lt;ul data-role="listview" data-inset="true" style="min-width: 270px;" data-theme="a" class="nav-search"&gt;
  &lt;li&gt;&lt;a href="#popupWaste" data-rel="popup" data-position-to="window" data-transition="pop"&gt;Add Waste&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#popupDownTime" data-rel="popup" data-position-to="window" data-transition="pop"&gt;Add Downtime&lt;/a&gt;&lt;/li&gt;
  
  &lt;/ul&gt;
  &lt;/div&gt;
  
  }
  </code></pre>