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
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");
}
以及前面提到的一些 SEO 问题。
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");
}
发布评论
评论(2)
这取决于上下文。以下是一些优点和缺点
优点:
缺点:
Martin
It depends on the context. Here are some pros and cons
Pros:
Cons:
Martin
这一切都取决于您的项目。
这里没有好坏之分,但是你必须记住没有启用 JS 的用户。如果您依赖 ajax 进行所有应用程序交互,那么您必须为那些不使用 JS(未启用浏览器 JS)的用户执行单独的行为。
这总是会在控制器级别导致类似的问题:
以及前面提到的一些 SEO 问题。
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:
And some SEO issues as mentioned.