Note that there are some explanatory texts on larger screens.

plurals
  1. POJQuery, updating form and exception if update it more then once
    primarykey
    data
    text
    <p>I've got index of my elements: </p> <pre><code>&lt;h2&gt;Index&lt;/h2&gt; &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function () { $('button').click(function () { $.post("Home/Swap", $("#log").serialize(), function (data) { $("#log").load("Home/Index #log"); }); }); }); &lt;/script&gt; &lt;form name="list" action="&lt;%=Url.Action("Post", "Home")%&gt;" method="post" id="log"&gt; &lt;% foreach (var k in Model) { %&gt; &lt;input type="checkbox" id="ids" name="ids" value="&lt;%=k.pos%&gt;" /&gt;&lt;%= k.pos %&gt;. To jest numer: &lt;%=k.name%&gt;&lt;br /&gt; &lt;% } %&gt; &lt;/form&gt; &lt;button&gt;Swap&lt;/button&gt; </code></pre> <p>and Swap method:</p> <pre><code> public ActionResult Swap(int[] ids) { int pos1=ids[0]; int pos2=ids[1]; Element element1 = (from t in db.Elements where t.pos == pos1 select t).Single(); Element element2 = (from t in db.Elements where t.pos == pos2 select t).Single(); element1.pos = pos2; element2.pos = pos1; db.SaveChanges(); return Index(); } </code></pre> <p>Everything works fine at the first swap of elements. But when I swap it once, and then try to swap another two I get an exception: </p> <blockquote> <p>System.NullReferenceException was unhandled by user code<br> Message=Object reference not set to an instance of an object.</p> </blockquote> <p>(exception from Swap Method) It's JQuery problem, Im sure. I susspect this <code>$("#log").load("Home/Index #log");</code> line - it shows me right result, but doesn't work fine if I try to do it more then once. how to fix it?</p> <p>edit: when I refresh page it works the same -> first works well, after getting an exception (the first touched elements are swaped after refreshing)</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.
    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