-1

I was asked to add a corporate header and footer in a webpage that I'm building. The design team gave me two links, one with the header and the another with the footer.

What I did was to open that link a then copy from the inspector the whole code, added in a _header.cshtml and _footer.cshtml. Then I included them as a partial view in the _layout.cshtml. I'm using ASP.net with MVC4.

This team made some changes in the header and footer and they told me that they could not see those changes in my page.

Could anyone please guide me and let me know what I have to do in order to have the header and footer working dynamical from those links that I received.

This is my code:

<body>   
   <header>
       <div>
           @Html.Partial("_Header")

           <!--#include virtual="/header.html"-->

       </div>
   </header>

       <div id="body">
           <section class="content-wrapper main-content clear-fix">
               @RenderBody()
           </section>
       </div>

   <footer>
       <div>       
           @Html.Partial("_Footer")

           <!--#include virtual="/footer.html"-->

       </div>
   </footer>
   @RenderSection("scripts", required: false)
</body> 

The links look like this one. http://webapps.corporate.com/templates/corporate/contact/header.html

Any help will be much appreciated.

MANUELAN00
  • 119
  • 8
  • Are _Header and _Footer at the same location of _Layout ? Take a look at https://docs.asp.net/en/latest/mvc/views/partial.html – vincentluth Oct 18 '16 at 01:25
  • No, but I can move them, that's not the problem. The header and footer are working fine because they are just partials views, my question is how to make them dynamics (get the header and footer from outsides links)? – MANUELAN00 Oct 18 '16 at 02:13
  • You might find it easier to simply use iframes. – Tieson T. Oct 18 '16 at 06:07

2 Answers2

0

You can use HtmlAgilityPack to parse the content of the site, an example on stack :

protected void Page_Load(object sender, EventArgs e)
{
    string Url = "http://www.metacritic.com/game/pc/halo-spartan-assault";
    HtmlWeb web = new HtmlWeb();
    HtmlDocument doc = web.Load(Url);

    string metascore = doc.DocumentNode.SelectNodes("//*[@id=\"main\"]/div[3]/div/div[2]/div[1]/div[1]/div/div/div[2]/a/span[1]")[0].InnerText;
    string userscore = doc.DocumentNode.SelectNodes("//*[@id=\"main\"]/div[3]/div/div[2]/div[1]/div[2]/div[1]/div/div[2]/a/span[1]")[0].InnerText;
    string summary = doc.DocumentNode.SelectNodes("//*[@id=\"main\"]/div[3]/div/div[2]/div[2]/div[1]/ul/li/span[2]/span/span[1]")[0].InnerText;
}

After getting the content string, you can populate it using Html.Raw into the partial view.

Community
  • 1
  • 1
vincentluth
  • 149
  • 5
  • It's a good approach but I don't want to use any third party tool.. I prefer to stay in the standard and supported functionality. – MANUELAN00 Oct 21 '16 at 05:05
0

Create two actions that return PartialResult' inside these actions, just connet to this remote view using HttpClient, cache the results and inside your Layout, use the@Html.RenderAction`

Otherwise, you have to copy the view content into the Header and Footer files that resides in the same directory as the Layout file

Haitham Shaddad
  • 4,336
  • 2
  • 14
  • 19
  • It wasn't me, I don't know who and why someone did it. I gave you a positive point...It's a valid point but I will answer what I found that answered my question. – MANUELAN00 Oct 21 '16 at 05:04