Why does Ajax.BeginForm replace my whole page?

后端 未结 6 1190
遇见更好的自我
遇见更好的自我 2020-12-16 09:47

Context: Asp.Net MVC3 w/Razor

I am trying to put a login form on a Razor layout (formerly master page) so that, when the user times out, s/he can be prompted to log

相关标签:
6条回答
  • 2020-12-16 10:04

    Late but correct. Make sure to reference the unobtrusive-ajax.js file as well as the MicrosoftAjax.js and MicrosoftMvcAjax.js files in that order. Works

    0 讨论(0)
  • 2020-12-16 10:05

    I had the same problem and solution was:

    • Check that UnobtrusiveJavaScriptEnabled is true.
    • Add reference to jquery.unobtrusive-ajax.js as Darin adviced.

    Unfortunatelly, it will not help for you because you set UnobtrusiveJavaScriptEnabled to false, but can help for somebody.

    0 讨论(0)
  • 2020-12-16 10:06

    Notice if you use Asp.Net template like I do, It bundles the file to bundles/jqueryval. So you have to add

    @Scripts.Render("~/bundles/jqueryval")
    

    to the page.

    0 讨论(0)
  • 2020-12-16 10:09

    Ajax.* helpers in ASP.NET MVC 3 use unobtrusive jquery so make sure that you have referenced the jquery.unobtrusive-ajax.js script in your view. Also you could use FireBug to see what's happening under the scenes and why the form doesn't send an AJAX request.

    Also the UpdateTargetId = "form" seems suspicious especially when your form has the refresh id: @id = "refresh". Is there some other element inside your DOM with id="form"? Maybe you meant UpdateTargetId = "refresh"?

    0 讨论(0)
  • 2020-12-16 10:15

    Besides checking if the .js is referenced, also check if no other form tags are being rendered. In my case, I had another form tag on the master page with the default action that was causing the whole page to reload.

    0 讨论(0)
  • 2020-12-16 10:18

    Note: my problem was first, i referenced wrong ajax script file jquery.validate.unobtrusive.min.js instead of jquery.unobtrusive-ajax.js and latest jquery version doesn't worked, only jquery-1.7.1.min.js worked for me.

    i was trying to return content after successful entry

    so here is the order:

    <script src="~/js/jquery-1.7.1.min.js"></script>
    <script src="~/js/jquery.validate.min.js"></script>
    <script src="~/js/jquery.unobtrusive-ajax.min.js"></script>
    

    Post of Darin and Richard Everett helped. hope helps.

    0 讨论(0)
提交回复
热议问题