Note that there are some explanatory texts on larger screens.

plurals
  1. POAsp.net mvc 2 form not posting to controller via Ajax
    text
    copied!<p>i'm trying to post a form to my controller via ajax so i can render a partial view. </p> <p>Here is my Ajax Code </p> <pre><code> var formCollection = $('#some-form'); $(function(){ $('#some-form').submit(function(){ $.ajax({ type: "POST", url: "/Trusk/Index", data: formCollection, dataType: "html", success: function (result) { $('#newView').html(result); }, error: function (request, status, error) { alert('Oh no!'); } }); }); }); </code></pre> <p>Code for my form, i want partial view to be render at ID = newView, The partial view is returned by the controller</p> <pre><code> &lt;% using (Html.BeginForm(new { @id = "some-form" })) { %&gt; &lt;div id="TestDiv"&gt; &lt;div id="Title"&gt;Test&lt;/div&gt; &lt;div id="CheckIn"&gt;Check-in:&lt;br /&gt; &lt;%:Html.TextBox("FromDate", "", new { @id = "DateFrom", @style = "width:190px" })%&gt;&lt;/div&gt; &lt;div id="CheckOut"&gt;Check-out:&lt;br /&gt; &lt;%:Html.TextBox("ToDate", "", new { @id = "DateTo", @style = "width:190px" })%&gt;&lt;br /&gt;&lt;/div&gt; &lt;div id="newView"&gt; &lt;/div&gt; &lt;input type="submit" value="Search" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;% } %&gt; </code></pre> <p>My controller code</p> <pre><code> public ActionResult Index(FormCollection post) { ITruckRepository hotelRep = new TruckRepository(); IEnumerable&lt;Truck&gt; AvailableTrucks = hotelRep.getTrucks('2012,3,2', '2012,3,5'); return PartialView("Search", AvailableTrucks ); } </code></pre> <p>Do i pass the correct parameter to the controller via Ajax?</p> <p>Thanks</p>
 

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