简体   繁体   English

MVC2 C#:如何用文件中的html填充contentplaceholder?

[英]MVC2 C#: How can I populate a contentplaceholder with html from a file?

So.. The issue I have came across is I am migrating a client's web app to MVC2, and the original method for displaying html content is not capable of working with MVC so I am needing to update it. 所以..我碰上了这个问题是我在迁移客户端的web应用程序MVC2,并显示HTML内容,原来的方法是不能够与MVC所以我需要更新它的工作的。 The functionality I need is like so: There is a side nav that will contain the actions, and say the user clicks on "FooBar" it will populate the "mainContent" placeholder with the "FooBar.html" file from a document directory. 我需要的功能是这样的:有一个包含操作的侧面导航,并说用户单击“ FooBar”,它将用文档目录中的“ FooBar.html”文件填充“ mainContent”占位符。 I would like to do this with no postbacks as well if it is possible. 如果可能的话,我也希望没有回发。 Any ideas? 有任何想法吗?

You may use jQuery ajax to load the pages when user clicks on the link. 当用户单击链接时,可以使用jQuery ajax加载页面。 load() function will be ideal here. 在这里, load()函数将是理想的。

It is just HTML and javascript . 它只是HTMLjavascript Nothing specific to ASP.NET MVC 没有特定于ASP.NET MVC的内容

//Include jQuery library
<div>
  <a href="Home/about" class="aLink" >About</a>
  <a href="Home/FAQ" class="aLink" >FAQ</a>
  <a href="Home/Contact" class="aLink" >Contact</a>
</div>
<div id="mainContent">


</div>

<script type="text/javascript">
 $(function(){
    $("a.aLink").click(function(e){
       e.preventDefault();  // prevent the default navigation behaviour
       $("#mainContent").load($(this).attr("href"));
    });
 });

</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM