i use to implement a search functionalities using ajax.beginform to return a partial view with my desired search and update the current view with the search results without requiring to reload the full pag., but lately i came over how to implement the
same functionality using java script directly and return the results as json format; So my question is what are the benefits of using each approach comparing to the other.
The main advantage is that you provide a "form context" to all input controls contained in the form. Without a form context no validation logic is automatically applied to the form on the server side. Thus, if you parse new ajax content for validation ...nothing
happens. However you can provide manually the form context in your View, or by writing an ad hoc ViewResult
Othere minor advantages are that it a little bitless code to write and less chnces to write something wrong. I computes the link automatically based on the action method name etc.
However, you have less flexibility. A direct call to the jQuery ajax give you more options. For instance you can receive also JSON instead of Html, do some pre-processing before attaching the new content and so on.
Personally, I have written a custom View Result to overcome the problem of the form context. This way I am free to choose among the two alternatives. I use Ajax form for simpler thing and direct calls when I need more options
thanks for your reply, actually i do not have that much experience in writing java script from scratch , but it seems that as you mentioned it can give me more flexibility if
i need more to implement complex scenarios. but at the end does any approach provide more light weight calls comparing to the other, or both approaches have the same performance effect on the server.
but at the end does any approach provide more light weight calls comparing to the other, or both approaches have the same performance effect on the server.
No matter which approach you use, they are both client side behavior, which is noen of the concern of the performance on the server. But use Jquery.ajax can give you more flexbility to post data, no only form.submit.
if you use Ajax.BeginForm with unobtrusive ajax, then your site degrades nicely when javascript is disabled. the part I dislike with Ajax forms is their use of global namespace for the callback functions. if you are writing a complex app with multiple forms
on the page, then this is a really bad feature. its even worse, if the form is on the page more than once (you lose local scoping for each form).
The main advantage is that you provide a "form context" to all input controls contained in the form. Without a form context no validation logic is automatically applied to the form on the server side. Thus, if you parse new ajax content for validation ...nothing
happens. However you can provide manually the form context in your View, or by writing an ad hoc ViewResult
Othere minor advantages are that it a little bitless code to write and less chnces to write something wrong. I computes the link automatically based on the action method name etc.
Sorry i came among this post again !!! , in the above quote you were talking about the advantages of of Ajax.actionlink and NOT the advantages of JQuery!!
Hi, yes advantagess of ajax acyion links or ajax.beginforms. Then I say that adbvantage of a direct call to jQuery ajax methods has mainly more flexibility, you can do things that cannot be done with action links and ajax forms,
Examples of more flexibility are:1) manipulating the data retrieved before attaching them to their traget location2) You can receive json and then use it to create the new content instead of sending html from the server saving Internet BansWidth 3) jQuery
ajax methods can be called programatically form javascript, while an action link...just works if someone click it...and so on.
As a general rule if what you need to do can be done with action links or ajax forms...do it this way otherwise back up to a direct call. Consider that also Ajax forms and links are built on top of jQuery ajax and at the end call jQuery ajax methods...but
they do some service more, but obviously restrict the usage...that's all.
johnjohn1231...
Participant
929 Points
885 Posts
Ajax.BeginForm Verus using javascript and Json to implement a search
Jul 14, 2011 03:37 AM|LINK
i use to implement a search functionalities using ajax.beginform to return a partial view with my desired search and update the current view with the search results without requiring to reload the full pag., but lately i came over how to implement the same functionality using java script directly and return the results as json format; So my question is what are the benefits of using each approach comparing to the other.
ignatandrei
All-Star
137651 Points
22144 Posts
Moderator
MVP
Re: Ajax.BeginForm Verus using javascript and Json to implement a search
Jul 14, 2011 03:52 AM|LINK
I like more the javascript . For me it is better as I have more control over it( error, return value, messages...)
francesco ab...
All-Star
20954 Points
3286 Posts
Re: Ajax.BeginForm Verus using javascript and Json to implement a search
Jul 14, 2011 07:22 AM|LINK
The main advantage is that you provide a "form context" to all input controls contained in the form. Without a form context no validation logic is automatically applied to the form on the server side. Thus, if you parse new ajax content for validation ...nothing happens. However you can provide manually the form context in your View, or by writing an ad hoc ViewResult
Othere minor advantages are that it a little bitless code to write and less chnces to write something wrong. I computes the link automatically based on the action method name etc.
However, you have less flexibility. A direct call to the jQuery ajax give you more options. For instance you can receive also JSON instead of Html, do some pre-processing before attaching the new content and so on.
Personally, I have written a custom View Result to overcome the problem of the form context. This way I am free to choose among the two alternatives. I use Ajax form for simpler thing and direct calls when I need more options
Mvc Controls Toolkit | Data Moving Plug-in Videos
johnjohn1231...
Participant
929 Points
885 Posts
Re: Ajax.BeginForm Verus using javascript and Json to implement a search
Jul 14, 2011 04:32 PM|LINK
thanks for your reply, actually i do not have that much experience in writing java script from scratch , but it seems that as you mentioned it can give me more flexibility if i need more to implement complex scenarios. but at the end does any approach provide more light weight calls comparing to the other, or both approaches have the same performance effect on the server.
Forest Cheng...
Star
8370 Points
819 Posts
Re: Ajax.BeginForm Verus using javascript and Json to implement a search
Jul 19, 2011 01:43 AM|LINK
Hi,
No matter which approach you use, they are both client side behavior, which is noen of the concern of the performance on the server. But use Jquery.ajax can give you more flexbility to post data, no only form.submit.
Hope this helpful,
Forest Cheng
If you have any feedback about my replies,please contact msdnmg@microsoft.com.
Microsoft One Code Framework
alstephen
Participant
1544 Points
513 Posts
Re: Ajax.BeginForm Verus using javascript and Json to implement a search
Jul 19, 2011 01:45 AM|LINK
maybe this can help you:
http://amirrajan.net/Blog/asp-mvc-ajax-begin-form-vs-jquery-dhtml-and-microtemplating
bruce (sqlwo...
All-Star
37604 Points
5573 Posts
Re: Ajax.BeginForm Verus using javascript and Json to implement a search
Jul 19, 2011 04:45 AM|LINK
if you use Ajax.BeginForm with unobtrusive ajax, then your site degrades nicely when javascript is disabled. the part I dislike with Ajax forms is their use of global namespace for the callback functions. if you are writing a complex app with multiple forms on the page, then this is a really bad feature. its even worse, if the form is on the page more than once (you lose local scoping for each form).
johnjohn1231...
Participant
929 Points
885 Posts
Re: Ajax.BeginForm Verus using javascript and Json to implement a search
Jul 24, 2011 03:17 AM|LINK
Sorry i came among this post again !!! , in the above quote you were talking about the advantages of of Ajax.actionlink and NOT the advantages of JQuery!!
BR
francesco ab...
All-Star
20954 Points
3286 Posts
Re: Ajax.BeginForm Verus using javascript and Json to implement a search
Jul 24, 2011 07:28 AM|LINK
Hi, yes advantagess of ajax acyion links or ajax.beginforms. Then I say that adbvantage of a direct call to jQuery ajax methods has mainly more flexibility, you can do things that cannot be done with action links and ajax forms,
Examples of more flexibility are:1) manipulating the data retrieved before attaching them to their traget location2) You can receive json and then use it to create the new content instead of sending html from the server saving Internet BansWidth 3) jQuery ajax methods can be called programatically form javascript, while an action link...just works if someone click it...and so on.
As a general rule if what you need to do can be done with action links or ajax forms...do it this way otherwise back up to a direct call. Consider that also Ajax forms and links are built on top of jQuery ajax and at the end call jQuery ajax methods...but they do some service more, but obviously restrict the usage...that's all.
Mvc Controls Toolkit | Data Moving Plug-in Videos