views:

266

answers:

3

I am a begineer in MVC and i need to know is it easy to use ajax with asp.net mvc ? i mean that if it is like asp applications when using ajax(JS file,web service or ajax toolkit)? I didn't try it b4 but what i need to know how can i use ajax with mvc application and i hope from any one give me an answer and put a link for articles about this topic not to put a link for general article about mvc i need a specific one about ajax with mvc and specially to be clear and with examples as i got confused from thoses articles that talked about this topic without any example.

I have read an article and noticed a code for calling ajax but i didn't understand it's structure so can any one tell me in steps and an example how to use ajax in MVC application? I am too sorry for this question that i restrict the answer but i am begineer in MVC and got confused and need a tutorial for any issue. And i need to know what are the consequences of using MVC in asp.net ? what are progress added to web programming after MVC is released in asp.net ? whate are improvements that had been added ?

Thanks in advance for any reply or answer

A: 

You've meshed up two questions into one. I'll try to address them both.

Using AJAX in ASP.NET-MVC is no different from using it in WebForms. You define an action on your controller and call it via jQuery (or any other javascript library).

Consequences of using ASP.NET-MVC? Hmm, this is a tough one. I prefer the MVC approach over WebForms because it's cleaner and easier to maintain later (this is just my viewpoint). I suggest that you read a good book on the subject, 'cos I have a feeling that you're not quite grasped the concept. I would really recommend Pro ASP NET MVC Framework.

Vnuk
SO on using Ajax in mvc is it like asp web forms or it need to add special code in the view for calling the web service for example?and on using the JQuery is it like the asp,net or differ in the syntax? these what i need to know so can u help me please?thanks
Ahmy
You should really read up on the subject. Code for calling web service should be the same in ASP.NET-MVC and WebForms. jQuery syntax for AJAX callback is definitely the same.
Vnuk
Execuse me, i didn't use jquery too much in ordinary asp.net but i used web service and javascript so my question is that i have to put script manager for calling web service like asp.net web forms? and with respect to jquery is it based upon calling method inside .cs in ordinary asp.net so it resemblesin mvc but calling method inside controller>?
Ahmy
+1  A: 

I echo the suggestions that you read up on the core concepts behind ajax. Once you do, the rest of my answer might be helpful to come back to :)

Back? Ok!

You will be very pleasantly surprised. You can really just include the jquery libs into your master page and then freely just use jquery in your views as you would in pure HTML.

Somehting I do is add a ContentPlaceHolder just before the close of the head tag int he site master template...

<asp:ContentPlaceHolder ID="JavascriptContent" runat="server" />

That way in my views, if I need some per view jQuery I can simply do somehting like..

<asp:Content ID="Content6" ContentPlaceHolderID="JavascriptContent" runat="server">
<script type="text/javascript">
    $(function() {
          alert("Hi!");
    });
</script>

And it just drops right in. On those pages where you don't need it, simply don't assign the placeholder.

Hope that helps!

Ken

Soulhuntre
By this way u called a JQuery libs ?????I need to cal a web service will this be like web forms by adding script manager and give web service path or it is different in mvc ajax? and do i need to add certain code for using ajax or calling web service and jquery is like that in asp.net web forms?
Ahmy
You are mixing apples and oranges. ScriptManager is used for AJAX calls, not web service calls. In ASP.NET-MVC you use jQuery instead of ScriptManager - it's much much better.
Vnuk
+1  A: 

This is how to emulate UpdatePanel in ASP.NET MVC.
This is how you can submit form with Ajax.
This is another sample of using built-in AjaxHelper.

Dmytrii Nagirniak