简体   繁体   中英

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. 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. 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. load() function will be ideal here.

It is just HTML and javascript . Nothing specific to 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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