开发者

Looking for suggestions on page updates without post backs

开发者 https://www.devze.com 2023-04-02 20:27 出处:网络
So I am working on a personal MVC project for practice.I like the responsiveness with using ajax calls to web services to update the page and not have to do an entire post back.

So I am working on a personal MVC project for practice. I like the responsiveness with using ajax calls to web services to update the page and not have to do an entire post back.

My knowledge is very limited and I am only aware of being able to do this with Javascript.

However, from a new developer's perspective, there is one problem with this. It would be assumed that you would need to carry out this same behavior through most of your site for any of your CRUD operations on your domain objects. Therefore causing (again for a new developer) the lack of handholding with Javascript (debugging, unit testing, strong type...etc).

But do to my lack of knowledge, is there a way you can acquire this same behavoir in MVC without having to perform all your crud operations with javascript/ajax calls to web se开发者_运维技巧rvices?

NOTE: before beating me up about my loose remarks of Javascript....I like Javascript, and there might be ways to negate some of the points I made with using it for all your CRUD operations to get the behavior I seek that I might just not be aware of.


Based on your question, it sounds like you're looking for an UpdatePanel for MVC. This control isn't valid for ASP.NET MVC, but you could accomplish similar functionality by using AJAX (either the Microsoft.Ajax lib or something like jQuery) and returning a PartialView from your controller. There's a decent tutorial on this technique on Telerik's site (just ignore the parts where they render their own controls -- you could render pretty much anything).

If this doesn't met your needs, the I believe, in order to accomplish an AJAX-like behavior on your page or pages, there will have to be some degree of JavaScript involved.

You may want to consider using a JavaScript framework like jQuery or MooTools in order to wrap the AJAX calling behavior, so that you just have to invoke the already-tested AJAX calls (e.g. jQuery.ajax()). Your JavaScript, then, would just be the callback handlers to update your pages.

On the server side, since you're using MVC (which I'm assuming is ASP.NET MVC), your controllers could just return a JsonResult instead of a ActionResult and just have your CRUD operations inside your controller instead of create a separate suite of web/WCF services. (You could also return an ActionResult to your jQuery.ajax() call, too.)

So I don't think you're going to be able to get away from JavaScript in order to accomplish AJAX-style behavior in your web site. You may not have to create a suite of web services as you could just have them contained within your controller.

This is probably going to get you what you want. You may want to check out a tutorial on the ASP.NET web site for some additional insight (but that won't get you to the unit testing part of your question).

0

精彩评论

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