Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Note that doing an ajax post will not refresh or redirect the page like a classic post would.</p> <p>The view is not showing because there is no where to place it. You post successfully, and return a view successfully but then do nothing with it. If you want to show the returned view, then you have to append it to the dom somehow. Here is a common method:</p> <pre><code>&lt;div id="successDiv"&gt;&lt;/div&gt; &lt;script type="text/javascript" language="javascript"&gt; $(document).ready(function () { $("#HotelDDL").change(function () { var text = $("#HotelDDL option:selected").text(); var value = $("#HotelDDL option:selected").val(); alert("Selected text=" + text + " Selected value= " + value); $.post("/Home/SearchForRooms", { HotelDDL: $("#HotelDDL option:selected").val() }, function(result){//add callback for success - result is the returned view $("#successDiv").html(result);//place the view inside of the div }); }); }); &lt;/script&gt; </code></pre> <p><code></code></p> <hr> <p><strong>Comment Response</strong></p> <p>@TunAntun - You should use a classic post if you want the view to have its own page. There is no way to accomplish this from ajax. You could do this with javascript though</p> <pre><code> $.post("/Home/SearchForRooms", { HotelDDL: $("#HotelDDL option:selected").val() }, function(result){//add callback for success - result is the returned view $("#successDiv").html(result);//place the view inside of the div }); </code></pre> <p>would become</p> <pre><code> var postForm = document.createElement("form"); postForm.setAttribute("method","post"); postForm.setAttribute("action","/Home/SearchForRooms"); var postVal = document.createElement("input"); postVal.setAttribute("type","hidden"); postVal.setAttribute("name","HotelDDL"); postVal.setAttribute("value",$("#HotelDDL option:selected").val() ); postForm.appendChild(postVal); document.body.appendChild(postForm); $(postForm).submit(); </code></pre> <p>This will dynamically issue the post you wanted. Then in your controller it will properly redirect or return a view. It is highly suggested that when returning a view from a <code>[HttpPost]</code> that you use <code>RedirectToAction</code> and then return the view from a <code>[HttpGet]</code> method in order to prevent refresh from reposting old data.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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