Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax call works great, but non-ajax call renders wrong in browser. What did I miss?
    primarykey
    data
    text
    <p>In a non-ajax call, the ordering of divs inside other divs gets messed up and the page renders wrong. When the same call is done via Ajax, the page renders perfectly.</p> <p>So I have this search form on my master page:</p> <pre><code> &lt;form action="&lt;%=Url.Action("Search") %&gt;" method="post" id="search1" class="search-form"&gt; Search: &lt;%=Html.TextBox("SearchBox1", null)%&gt; &lt;input type="submit" value="Go" /&gt; &lt;/form&gt; ..... &lt;div id="search-results"&gt; &lt;asp:ContentPlaceHolder ID="MainContent" runat="server" /&gt; &lt;/div&gt; </code></pre> <p>I also have this javascript to submit the search form using Ajax:</p> <pre><code>$('.search-form').ajaxSubmit(GetSearchAjaxFormOptions()); </code></pre> <p>and</p> <pre><code>function GetSearchAjaxFormOptions() { return { target: '#search-results', data: GetSearchData(), success: RunAfterAjaxSubmit() }; } </code></pre> <p>when the form is sumbitted via Ajax, everything renders beautifully. When I turn Ajax off and submit the form, The rendered html is messed up. Like there was a misplaced element or something in there. The divs on the page do not end up inside the right divs. I looked at and diffed and ... all sorts of thing to find the difference, and I cant see any thing that would cause this.</p> <p>My controller method is:</p> <pre><code>public ActionResult Search() { if (Request.IsAjaxRequest()) { return View("SearchResultsPartial", sm); } else { return View("Index", sm); } </code></pre> <p>}</p> <p>My Index.aspx is:</p> <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %&gt; &lt;asp:Content ID="indexTitle" ContentPlaceHolderID="TitleContent" runat="server"&gt; Home Page &lt;/asp:Content&gt; &lt;asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server"&gt; Html.RenderPartial("SearchResultsPartial"); &lt;/asp:Content&gt; </code></pre> <p>and my SearchResultsPartial.ascx is: </p> <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;MyWebSite.Models.SearchModel&gt;" %&gt; &lt;% int count = Model.searchResults.Count(); for (int i = 0; i &lt; count; i++) { Response.Write(Model.searchResults.ElementAt(i)); } %&gt; </code></pre> <p>My model has:</p> <pre><code>public IEnumerable&lt;String&gt; searchResults; </code></pre> <p>So an important thing is that the search engine returns to the model a collection of strings. Each string is an html of a search result. This was generated by using linq to xml and is really the result of the XElement.ToString() call.</p> <p>And my master page has:</p> <pre><code>&lt;div id="search-results" class="yui-u"&gt; &lt;asp:ContentPlaceHolder ID="MainContent" runat="server" /&gt; &lt;/div&gt; </code></pre> <p>Any help in finding what to do to fix this is most appreciated. I have ran out of things to look at myself.</p> <p>Many thanks!</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. 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