c# - 如何加载独立于 site.master 的 View ?

标签 c# jquery asp.net-mvc asp.net-ajax

我正在准备一个我用 ASP.Net MVC 编写的应用程序,用于一些简单的 Ajax-y 内容。基本上,我希望用户能够在不重新加载页面的情况下转到页面的不同部分。

为此,我希望能够重新加载我的页面正文。

我的网站大师被分解为头部 body 和 footer 。我希望能够使用 $("body").load(whateverlink) 之类的东西来刷新主体,但在我的情况下,这样做会导致网站在主体内呈现。

我怎样才能成功做到这一点?

编辑:页面由 View 组成,而不是部分 View 。从理论上讲,我可以将所有页面转换为部分页面,但如果可能的话,我正在寻找解决方法。 谢谢

最佳答案

您可以让您的 Controller 返回部分 View ,使用 JQuery 发出请求并用您的页面内容更新 div:

JQuery:

function navigate(url){
  $.ajax({
    url: "/Home/Index",
    cache: false,
    success: function(html){
       $("#content").html(html);
      }
   });
}

Controller :

public class HomeController : Controller
{    
    public void Index()
    {
       return this.PartialView();
    }
}

关于c# - 如何加载独立于 site.master 的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2043023/

相关文章:

javascript - 如何让弹出窗口在 3 秒后消失

jquery - 成功时重定向并失败时显示错误

javascript - 将 Button 静态添加到父 div

php - Jquery/Ajax 在 PHP 页面上的 for 循环中使用

c# - 系统.OutOfMemoryException : Exception of type 'System.OutOfMemoryException' was thrown in angularjs

c# - 我应该如何在我的业务/服务/应用程序层之间使用异步等待

c# - 正则表达式语法停止搜索

c# - 在客户端-服务器之间传递可空值的最佳方式

c# - ReSharper/Linq 错误 : Access to modified closure

c# - 实现插件架构 - 动态 DLL 加载