Only calling action through Ajax Call
Based on this question (Link) I want to know if is good to have a mvc application just using ajax call?
Th开发者_高级运维anks, Pedro
It depends on the context. Here are some pros and cons
Pros:
- An application which has multiple sections which need to be updated independently will be easier to write using ajax calls because you don't need to maintain the state of each section over postback.
- Smaller web requests -> better performance
- No need to maintain scrolled position of window, a full postback would otherwise scroll to the top of the page
Cons:
- Difficult to design so that its current state can be bookmarked
- Not navigatable by search engines
- Back/forward buttons don't work without quite a bit of effort
- Requires javascript to be enabled
Martin
It all depends on your project.
There is no good or bad approach here, but you must remember users that does not have JS enabled. If you depend on ajax for all the app interactions then you must do a separate behaviour for those users that does not use JS (browser JS not enabled).
That always lead to something like this at controller level:
public ActionResult Index()
{
if (Request.IsAjaxRequest())
{
//Ajax Request
//Return partial mostly for partial refresh of the page
return View("PartialView");
}
//Regular Request
return View("FullView");
}
And some SEO issues as mentioned.
精彩评论