开发者

Need a good tutorial on asp.net MVC2 AJAX for a Rails programmer [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 8 years ago.

Improve this question

Making my own asp.net MVC2 web app for the first time. I've been using Rails for almost 3 years now and consider myself to be pretty proficient with that framework. Switching ove开发者_开发百科r, I've been reading some pdfs and so far I am impressed at what asp.net has to offer. My web app will have a ton of javascript in it and I'm going to use JQuery. I've read NerdDinner's PDFs on AJAX but they still don't seem to give me what I want. For example, in Rails, I can make an AJAX call back to my controller that then renders a js partial, and in that partial, I am able to access different variables to update my view. What's the asp.net equivalent of that? Are there any tutorials that can better help me understand how asp.net handles AJAX?


The js partial in Rails is very nice. I don't know that there's an equivalent in ASP.NET MVC. One thing you could do is just serialize your object to JSON. Then in your callback, you can use the properties of your JSON object to dynamically update your HTML with JavaScript. I often take this approach. Hope that helps.

Edit

Here's an example

// controller
public ActionResult MyContrivedEndpoint()
{
    var response = new
    {
        Foo = "Bar",
        Bar = "Baz"
    };

    return Json(response, JsonRequestBehavior.AllowGet);
}

// javascript
$.get(myUrl, mySuccessFunction);

function mySuccessFunction(response) {
    $('#foo').html(response.Foo);
    $('#bar').html(response.Bar);
}

Edit

Another option would be to just return a normal aspx view. In this case, the response would just be HTML and you can drop it into a div. Your aspx view could contain some script tags that modify the DOM on $(document).ready()

Always more than one way to skin a cat!


check out nikhil's blog post on ajax with asp.net mvc framework
Also have a look at the following
http://haacked.com/archive/2008/07/29/super-simple-mvc-ajax-with-jquery-demo.aspx
http://www.chrisvandesteeg.nl/2007/12/19/ajax-and-json-for-aspnet-mvc-with-jquery/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜