Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC4 calling Javascript function from View
    primarykey
    data
    text
    <p>The code below works if you enter a city and state, then click outside of the text box but NOT directly on the Search submit button. Clicking outside of the text box triggers the onblur event which fires the javascript code to run a bing maps geocode on the city and state and populates the two hidden text boxes with the latitude and longitude. THEN when you click the submit button the code passes the latitude and longitude into the CityDistanceSort action on the Job controller which sorts the cities in the database based on their distance from the latitude and longitude passed in, then posts that sorted model to the view. Everything works except that you need to be able to enter the City and State and then of course just click the Submit button directly. But doing so doesn't give the JS code time to geocode and causes an error: The parameters dictionary contains a null entry for parameter 'SearchLatitude' of non-nullable type 'System.Double...</p> <pre><code>@using(Html.BeginForm("CityDistanceSort", "Job")) { &lt;input type="hidden" name="SearchLatitude" id="SearchLatitude"&gt; &lt;input type="hidden" name="SearchLongitude" id="SearchLongitude"&gt; &lt;input type="text" name="CityStateName" id="CityStateName" placeholder="CITY, BY DISTANCE" onblur="GeocodeSearchCityState()"&gt; &lt;input type="submit" value="SEARCH" /&gt; } </code></pre> <hr> <pre><code> [HttpPost] public ActionResult CityDistanceSort(double SearchLatitude, double SearchLongitude) { var model = db.Jobs.ToList(); foreach (var item in model) { item.PickupDistanceSort = ICN.CustomMethods.GetDistance(SearchLatitude, SearchLongitude, item.PickupLatitude, item.PickupLongitude); } return View("JobHeadings", model.OrderBy(s =&gt; s.PickupDistanceSort)); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload