Thursday, February 5, 2015

Filled Under:

What is AJAX Helpers in ASP.NET MVC

Ajax helper in ASP.NET MVC essentially provides Ajax functionality for your web applications. AJAX Helpers are used for creating AJAX enabled elements for example Ajax enabled forms and links which performs request asynchronously. when you use Ajax helper you can submit your HTML form using Ajax so that instead of refreshing the full web page only a part of it can be refreshed. you can render action links that allow you invoking action methods using Ajax. Basically AJAX Helpers are extension methods of AJAX Helper class which exists in System.Web.Mvc.Ajax namespace.

AJAX-enabled link based example:-

Here I have created a example to show how to use AJAX action link using action and controller in Asp.Net MVC.

@Ajax.ActionLink("Fatch Data""GetData"new AjaxOptions {UpdateTargetId = "Data-container", HttpMethod = "GET" })


Unobtrusive AJAX in MVC?

Unobtrusive Validation and AJAX support in  MVC follows  best practices that enable Progressive Enhancement and also easy to use. The unobtrusive AJAX library (not the unobtrusive validation library) is admittedly a bit limited in functionality, but if it fulfill the requirements of the application you are writing, then by all means use it. And because the source code of it is in your app (it's JavaScript, after all), it's generally straightforward to make any updates or changes to it as you see fit.
Configuration options for AJAX Helpers
 It is very important to know the AjaxOptions class defines properties that allow you to specify callbacks for different stages in the AJAX request life cycle. There are several properties in AjaxOptions. Now You can use these property as par different scenario and different requirements. There are following properties provided by AjaxOptions class for AJAX helpers:

Url : Specify the URL that will be requested from the server.

Confirm: Specify a message that will be displayed in a confirm dialog to the end user.When user
clicks on OK button in the confirmation dialog, the Ajax call performs.

OnBegin: Specify a JavaScript function name which is called at the beginning of the Ajax request.

OnComplete: Specify a JavaScript function name which is called at the end of the Ajax request.

OnSuccess:  Specify a JavaScript function name which is called when the Ajax request is successful.

OnFailure:  Specify a JavaScript function name which is called if the Ajax request fails.

LoadingElement:  Specify progress message container’s Id to display a progress message or animation to the end user while an Ajax request is being made.

LoadingElementDuration: Specify a time duration in milliseconds that controls the duration of the progress message or animation.

UpdateTargetId: Specify the target container’s Id that will be populated with the HTML returned by the
action method.
InsertionMode: Specify the way of populating the target container. The possible values are InsertAfter, InsertBefore and Replace (which is the default).

Cross Domain AJAX (CORS)?
Cross-domain requests require mutual consent between the Web page and the server. You can initiate a cross-domain request in your Web page by creating an XDomainRequest object off the window object and opening a connection to a particular domain. The browser will request data from the domain's server by sending an Origin header with the value of the origin. It will only complete the connection if the server responds with an Access-Control-Allow-Origin header of either * or the exact URL of the requesting page. By default in ASP.NET MVC, any web browsers allows AJAX calls only to our web application’s site of origin. This will allow us to prevent various security issues. In that case, you have two options: Either add CORS header "Access-Control-Allow-Origin: *" to the response (and configure the client ajax() call with dataType:"html"), or create a special JSON(P) page that delivers the same data as JSON (with padding) (and configure the client ajax() call like in the OP, with dataType:"jsonp").

If you like this post share it.. If you encounter any problems, feel free and comment below to find solution. Share Your Experience with us.




16 comments:

  1. Smartmind Online Training provides complete knowledge regarding all core concepts and it gives enough confidence about Dotnet. We can say Smartmind Online Training  is the best Dotnet Training platform for freshers because here we start every concept from the ground level and we explain concepts by taking real time scenarios, so Students get good understanding about subject. Smartmind Online Training  helps you to gain depth knowledge on Dotnet and it makes you ready to become a real time Software Developers
    Dotnet Online Training

    ReplyDelete
  2. This is very good information for knowing the dotnet basic knowledage dotnetonlinetraining

    ReplyDelete
  3. Wow what a cool blog you have here! I am impressed. You really put a lot of time and effort into this. I wish I had your creative writing skills, progressive talent and self discipline to produce a blog like you did.
    Great information provided about MVC Training . I appreciate your work.

    ReplyDelete
  4. We have develop the apps with different versions with Visual Studio 11 Beta? Sure, you can multi-target all these versions and even plugin more targeting packs. I'll do a blog post later this week on Portable Libraries, a new version in .NET 4.5 that makes creating libraries for any CLR (including Xbox, Phone, Mono and others).

    dotnet training in chennai

    ReplyDelete
  5. After looking into a handful of the blog articles on your site, I really like your technique of writing a blog. I book marked it to my bookmark site list and will be checking back in the near future. Take a look at my website as well and let me know your opinion.

    Vitiligo Treatment
    Psoriasis Treatment
    Dry Skin Treatment

    ReplyDelete
  6. This is very good information for knowing the dotnet basic knowledage, Most of the institutes are providing asp.net with mvc online training institute in Ameerpet.

    ReplyDelete
  7. Thanks for your informative article. Really useful concept.ajax helperes explained very well thank youDot Net Training in Chennai

    ReplyDelete
  8. Nice article. I have suggested to my friends to go through this blog. Thank you for sharing this useful information.If you want to learn dotnet course in online, please visit below site.
    dotnet Online Training, dotnet course, dotnet online training in kurnool, dotnet online training in hyderabad, dotnet online training in bangalore, online courses, online learning, online education, trending courses, best career courses

    ReplyDelete
  9. The style of writing is excellent and also the content is top-notch. Thanks for that shrewdness you provide the readers! to read. I never stop myself to say something about it. You’re doing a great job. Keep it up...
    Very useful blog thanks for sharing IndPac India the German technology Packaging and sealing machines in India is the leading manufacturer and exporter of I hope I will see again. You can use this for any quantum realm white jacket kind of academic writing work.


    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery



    ReplyDelete
  10. Howdy, I think your blog may be having internet browser compatibility issues. When I take a look at your site in Safari, it looks fine however, when opening in IE, it's got some overlapping issues. I just wanted to give you a quick heads up! Aside from that, excellent site!
    Technology

    ReplyDelete