asp.net MVC3 and jquery AJAX tutorial [closed]

2020-02-29 01:29发布

问题:

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 7 years ago.

I need a very detailed ebook/tutorial/video in very simple language for jquery AJAX and JSON with asp.net MVC3 . I have been googling but could't find any good one. Please send me links.

Thanks.

回答1:

From a client side use $.ajax:

$.ajax({
   type: "POST",
   url: "users/save",
   data: "name=John&location=Boston",
   success: function(msg){
     alert( "Data Saved: " + msg );
   }

From a server side handle ajax requests:

public ActionResult Save(string name, string location)
{
  //Save data

  return new JsonResult(){Data = "User was saved!"};
}

Use JsonResult to return json string to the client and JSON.parse to parse json string at the client side.

To simplify ajax calls you can also create wrappers around $.ajax and JsonResult, define your ajax requests structure like {data:"jsonString", messagess: [], redirect_url } etc.

That's all tutorial.



回答2:

http://haacked.com/archive/2010/04/15/sending-json-to-an-asp-net-mvc-action-method-argument.aspx



回答3:

You could try one of the sessions from the MVCConf presented by Eric Sowell (@Mallioch). It is a good tutorial and so are quite a number.



回答4:

Eric Sowell was mentioned above.

The link to his talk is:

Evolving Practices in Using jQuery and Ajax in ASP.NET MVC Applications

You need to understand JavaScript prototypes to understand, or rather, be able to use the recommended practice.

But it is well worth it. You end up with a VERY reusable pattern for ALL the javascript in your apps, not just the AJAX bits.

Plus you have something to bang your head against until you really understand JavaScript, as opposed to Cookbook recipes for jQuery.

Ie, if you don't structure your jQuery/JS in some way, you will end up with a bowl of spaghetti.

Other books: David Crockford wrote a short book: Javascript, the Good Parts. This explains prototypes and a lot else, very concisely. There is also a GREAT article in MSDN Magazine, May 2007 by Ray Djajadinata:

JavaScript: Create Advanced Web Applications with Object-Oriented Techniques

If you read that article ten times, you will understand JavaScript.



回答5:

Did you try the official Microsoft resources?