Why doesn't Request.IsAjaxRequest() work in ASP.NET MVC 3?

后端 未结 1 587
有刺的猬
有刺的猬 2020-12-19 17:05

I\'m creating a new project, asp.net mvc3 with Razor, and wanting to turn the LogOn into an ajax request.

HTML

@using (Ajax.BeginForm(\"LogOn\", \"Ac         


        
1条回答
  •  悲&欢浪女
    2020-12-19 17:30

    That's because by default ASP.NET MVC 3 uses jQuery and unobtrusive AJAX instead of the MicrosoftAjax* library. This means that when you write Ajax.BeginForm you will need to include the proper scripts inside your page:

    
    

    and in your web.config make sure that you have unobtrusive javascript enabled:

     
    

    Now you can safely throw away all MicrosoftAjax* script references on your page if you had any, they are no longer used.

    This being said personally I never used any of the Ajax.* helpers. I always prefer to have control. So I would write:

    @using (Html.BeginForm("LogOn", "Account"))
    {
    }
    

    and then AJAXify this form using the jquery form plugin:

    $(function() {
        $('form').ajaxForm(function(result) {
            alert('form successfully submitted');
        });
    });
    

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