c# - Why is Ajax.BeginForm not working? -
i looked @ several similar questions, can't working.
i have radio buttons in form. instead of selecting option , clicking submit button, want submit form when user clicks radio button.
so hid submit button , placed javascript function emulates click of button (i tried working button click, doesn't seem problem).
in view have:
<script type="text/javascript" src="/scripts/jquery-1.9.1/jquery-1.9.1.min.js" ></script> <script type="text/javascript" src="/scripts/jquery-1.9.1/jquery.unobtrusive-ajax.min.js"></script> <script type="text/javascript"> function change() { $('#buttonradio').click(); } </script> <h2>dashboard</h2> <div class="dashboard" id="itemsdshbrd" style="overflow:auto;height:97%;"> <div id="dshbrdradiogroup" style="float:right;font-size:small"> <% using (ajax.beginform("index", "dshbrd", new { value = 1 }, new ajaxoptions { httpmethod = "post", updatetargetid = "stations" })) { %> <input class="radioclass" id="r1" name="radiogroup" type="radio" value="1" onclick="change()" checked/> <input class="radioclass" id="r2" name="radiogroup" type="radio" value="2" onclick="change()"/> b <input class="radioclass" id="r3" name="radiogroup" type="radio" value="3" onclick="change()"/> c <input class="radioclass" id="r4" name="radiogroup" type="radio" value="4" onclick="change()"/> d <input id="buttonradio" type="submit" value="submit" style="visibility:hidden"/> <% } %> </div> <div id="stations"> <% html.renderpartial("~/views/dshbrd/stations.ascx"); %> </div> </div>
*i know i'm sending value = 1.
in controller have:
[httppost] public actionresult index(int value) { if (request.isajaxrequest()) { return partialview("~/views/dshbrd/stations.aspx"); } return view("~/views/dshbrd/index.aspx"); }
where request.isajaxrequest()
never true.
my web.config ok:
<add key="clientvalidationenabled" value="true" /> <add key="unobtrusivejavascriptenabled" value="true" />
any ideas?
i don't think you're submitting form correctly.
try removing submit button altogether, , replacing change code with:
function change() { $("#dshbrdradiogroup form").submit(); }
it sounds unobtrusive ajax isn't working correctly. check following:
- clientvalidationenabled true in web.config app settings.
- unobtrusivejavascriptenabled true in web.config app settings.
- your referencing jquery.unobtrusive-ajax.min.js script on page somewhere.
Comments
Post a Comment