asp.net - Ajax form reloading/returning new page instead of updating -


i'm trying hand , asp.net mvc 4 , having issue ajax form returning whole new page instead of updating div.

here's razor html code:

<div class="all">     <div class="search">         @using (ajax.beginform( new ajaxoptions { updatetargetid = "currentsku" } ))         {         @html.label("enter sku:")         @html.textbox("textbox1")         <input type="submit" value="find" />         }     </div>     <div id="currentsku">         <span>no sku selected.</span>     </div> 

and here's controller:

    public actionresult index()     {         // pay no attention this, place holder         return view( db.xinventoryext.take(1) );     }      [httppost]     public actionresult index(string textbox1)     {         if (db.xinventoryext.count(a => a.invtid == textbox1) < 1)         {             return content("sku not found.", "text/html");         }          var ret = db.xinventoryext.first(b => b.invtid == textbox1);          return content(ret.tostring(), "text/html");     } 

i reading happens when not including microsoftajax.debug.js can't find copy of file anywhere.

i reading happens when not including microsoftajax.debug.js

actually need include jquery.unobtrusive-ajax.js script. microsoftajax.debug.js part of older versions of asp.net mvc , obsolete now. if using asp.net mvc 4 , using default bundles (~/app_start/bundleconfig.cs), in _layout.cshtml have following towards end of dom:

@scripts.render("~/bundles/jquery") @scripts.render("~/bundles/jqueryval") @rendersection("scripts", required: false) 

now ajax.* helpers work , have enabled unobtrusive jquery validation. happen because of way ~/bundles/jqueryval bundle defined:

bundles.add(new scriptbundle("~/bundles/jqueryval").include(             "~/scripts/jquery.unobtrusive*",             "~/scripts/jquery.validate*")); 

if not using bundles include corresponding scripts in order:

<script type="text/javascript" src="~/scripts/jquery-1.8.2.js"></script> <script type="text/javascript" src="~/scripts/jquery.unobtrusive-ajax.js"></script> @rendersection("scripts", required: false) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -