asp.net mvc - Using Ajax gives stale results -


edit

my ajax form gets correct id update content , replace option. submitting clicking <input type="submit" value="submit!" />.

problem: when clicked on submit didn't see update. second trial gave expected result. when refreshed page lost record (first hit successful) on spot.

model

[serializable] public abstract class abstractentity {     public guid id { get; set; }     public datetime lastmodified { get; set; } }  [serializable] public class product : abstractentity {     public product() {         this.attachments = new hashset<attachment>();     }     public string title { get; set; }             public string commentary { get; set; }     public datetime placedon { get; set; }     public string user { get; set; }     public icollection<attachment> attachments { get; set; } }  [serializable] public class attachment {     public string mimetype { get; set; }     public string description { get; set; }     public string filename { get; set; } } 

controller

[handleerror] public class productcontroller : controller {     private readonly idocumentsession documentsession;      public productcontroller(idocumentsession documentsession) {         this.documentsession = documentsession;     }      public actionresult listrecent() {         return view(listall());     }      [audit, httppost]     public actionresult delete(guid id) {         documentsession.delete<product>(documentsession.load<product>(id));         documentsession.savechanges();         return partialview("productslist", listall());     }      [audit, httppost]     public actionresult create(product product) {         if(modelstate.isvalid) {             documentsession.store(product);              documentsession.savechanges();         }         return partialview("productslist", listall());     }      private ienumerable<product> listall() {         return documentsession.query<product>().toarray();     } } 

views ('scriptless')

layout

<head>     <title>@viewbag.title</title>             <link href="@url.content("~/content/stylesheets/normalize.css")" rel="stylesheet" type="text/css" />     <link href="@url.content("~/content/stylesheets/site.core.css")" rel="stylesheet" type="text/css" />     <script src="@url.content("~/scripts/jquery-1.7.2.js")" type="text/javascript"></script>     <script src="@url.content("~/scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script> </head> <body>     <div id="main-wrapper">         <div id="header">[@html.actionlink("list", "listrecent", "product")]</div>         <div id="content">@renderbody()</div>     </div>         </body> 

listrecent.cshtml

@model ienumerable<lamp.domainlayer.entities.product> @{      viewbag.title = "listrecent";     var options = new ajaxoptions {         insertionmode = insertionmode.replace,         updatetargetid = "productslist"             }; }  <h2>list</h2>  @html.partial("productslist", model)  @using(ajax.beginform("create", "product", options)) {     <fieldset>         <p>             <label class="autowidth">title</label>             @html.editor("title")             @html.validationmessage("title")         </p>         <p>             <label class="autowidth">commentary</label>             @html.textarea("commentary")             @html.validationmessage("commentary")         </p>         @* fields have omitted.. *@          <input type="submit" value="submit" />         <input type="reset" value="clear" />      </fieldset> } 

productslist.cshtml

@model ienumerable<lamp.domainlayer.entities.product> @{     var options = new ajaxoptions {         insertionmode = insertionmode.replace,         updatetargetid = "productslist"     }; }  <div id="productslist">     @foreach(var p in model) {         <div class="productcard">             <p class="title"><strong>title</strong>: @p.title</p>             <p class="author"><strong>user</strong>: @p.user</p>             <p class="date"><strong>placed on</strong>: @idea.placedon.toshortdatestring()</p>             <p class="link">@html.actionlink("details", "details", "product")</p>             <p class="link">                 @using(ajax.beginform("delete", "product", new { id = p.id }, options))  {                                     <input type="submit" value="you!" />                 }             </p>         </div>     } </div> 

i guess ie's fault (precisely way,how ie cache ajax requests). here-it solution:

http://viralpatel.net/blogs/ajax-cache-problem-in-ie/


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -