How to include the meta keyword and meta description in the page? - keyword

I have the following code:
<%# Page Title="Spam Filter, Free Exchange Spam Filter – Software to Stop Spam" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentBreadCrumb" Runat="Server">
Welcome to > Home
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentBodyMain" Runat="Server">

You can use the <asp:HtmlMeta> control. On the .aspx file you write:
<asp:HtmlMeta ID="descriptionMeta" runat="server" />
<asp:HtmlMeta ID="keywordMeta" runat="server" />
Then, from the code, you can do this to set content etc.
this.descriptionMeta.Name = "description";
this.descriptionMeta.Content = "description of the page or whatever";
this.keywordMeta.Name = "keywords";
this.keywordMeta.Content = "some,keywords,and,things";

Related

MVC- How can I let my content page add an extra ContentPlaceHolder?

I have a content page inherited from master page.
There are two ContentPlaceHolder in master page.
The master page like:
<html>
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
</head>
<body>
<div id="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</body>
</html>
The content page like:
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>
My problem is when i add an extra ContentPlaceHolder in the master page like that:
<html>
<head runat="server">
<title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
</head>
<body>
<div id="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<asp:ContentPlaceHolder ID="MainContent2" runat="server" />
</div>
</body>
</html>
the content page still are two <asp:Content> in it like:
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>
I have try refresh the content page and establish the project again but still are two <asp:Content> in the content page. Did I miss something? Can someone please give me help?
As far as i know Visual Studio don't update your content pages if you add a new ContentPlaceHolder in your master Page.
You need to add to your page manually.
like this.
In Master Page if you added below:
<asp:ContentPlaceHolder ID="newcontentplaceholder" runat="server">
</asp:ContentPlaceHolder>
In content Page add
<asp:Content ID="Content3" ContentPlaceHolderID="newcontentplaceholder" runat="server">
</asp:Content>

Nested content place holders

I want my master page to be divided in two parts - left and right.
Here's is how I do it:
The master page:
<section id="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server">
<div>
<asp:ContentPlaceHolder ID="left" runat="server" />
</div>
<div>
<asp:ContentPlaceHolder ID="right" runat="server" />
</div>
</section>
</asp:ContentPlaceHolder >
The About view:
<asp:Content ID="aboutContent" ContentPlaceHolderID="MainContent" runat="server">
<asp:Content ID="leftHome" ContentPlaceHolderID="left" runat="server">
<h2>About</h2>
</asp:Content>
<asp:Content ID="rightHome" ContentPlaceHolderID="right" runat="server">
<h2>About</h2>
</asp:Content>
</asp:Content>
I get the error: Content controls have to be top-level controls in a content page or a nested master page that references a master page.
How to resolve this?
You cannot have such nesting. Here's what you could do in the masterpage:
<section id="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
<div>
<asp:ContentPlaceHolder ID="left" runat="server" />
</div>
<div>
<asp:ContentPlaceHolder ID="right" runat="server" />
</div>
</section>
and in the view:
<asp:Content ID="leftHome" ContentPlaceHolderID="left" runat="server">
<h2>Left content</h2>
</asp:Content>
<asp:Content ID="rightHome" ContentPlaceHolderID="right" runat="server">
<h2>Right content</h2>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
some main content
</asp:Content>

Nested MVC master pages

I'm, using MVC to develop a Web application, and I need to use nested MasterPages in my site, in order to share the Visual Components.
I have two Master Pages and a ContentPage:
Parent.master
Child.master
Content.aspx
I want to reference a ContentPlaceHolder placed on the top Parent.master from the Content view that has Child.master as MasterPage. It seems that I can use the ContentPlaceHolders from the direct parent, but not from the indirect parent. Let's see with a sample:
Parent.master
<%# Master Language="C#"
Inherits="System.Web.Mvc.ViewMasterPage"%>
<HTML>
<head runat="server">
<title>
<asp:contentplaceholder id="Title" runat="server" />
</title>
</head>
<body>
<asp:contentplaceholder id="Body" runat="server" />
</body>
<HTML>
Child.Master
<%# Master Language="C#" MasterPageFile="~/Views/Shared/Parent.master"
Inherits="System.Web.Mvc.ViewMasterPage"%>
<asp:Content ID="BodyContent" ContentPlaceHolderID="Body" runat="server">
<asp:contentplaceholder id="Body1" runat="server" />
<asp:contentplaceholder id="Body2" runat="server" />
</asp:Content>
Content.aspx
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Child.master"
Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="TitleContent" ContentPlaceHolderID="Title" runat="server">
<!-- Placed to the top parent Master page (does not work) -->
The page title
</asp:Content>
<asp:Content ID="Body1Content" ContentPlaceHolderID="Body1" runat="server">
<!-- Placed in the direct parent Master page (Works) -->
Body content 1
</asp:Content>
<asp:Content ID="Body2Content ContentPlaceHolderID="Body2" runat="server">
<!-- Placed in the direct parent Master page (Works) -->
Body content 2
</asp:Content>
The result is that I can see Body content 1 and Body content 2 in my page, but not the page title.
The content place holder will only refer to the content placeholders in its immediate parent. Change your Child.master this this:
<%# Master Language="C#" MasterPageFile="~/Views/Shared/Parent.master" Inherits="System.Web.Mvc.ViewMasterPage"%>
<asp:Content ID="BodyContent" ContentPlaceHolderID="Body" runat="server">
<asp:Content ContentPlaceHolderID="Title" runat="server">
<asp:contentplaceholder id="TitleContent" runat="server" />
</asp:Content>
<asp:contentplaceholder id="Body1" runat="server" />
<asp:contentplaceholder id="Body2" runat="server" />
</asp:Content>
So the Child.master essentially acts like a "pass-through" for the Title content placeholder.
I'm pretty sure you have to add your title place holder in your child.master
<%# Master Language="C#" MasterPageFile="~/Views/Shared/Parent.master"
Inherits="System.Web.Mvc.ViewMasterPage"%>
<asp:Content ID="TitleContent" ContentPlaceHolderID="Title" runat="server" />
<asp:Content ID="BodyContent" ContentPlaceHolderID="Body" runat="server">
<asp:contentplaceholder id="Body1" runat="server" />
<asp:contentplaceholder id="Body2" runat="server" />
</asp:Content>
and in your view
<%# Page Language="C#" MasterPageFile="~/Views/Shared/Child.master"
Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="TitleContent1" ContentPlaceHolderID="TitleContent" runat="server">
<!-- Placed to the top parent Master page (does not work) -->
The page title
</asp:Content>
<asp:Content ID="Body1Content" ContentPlaceHolderID="Body1" runat="server">
<!-- Placed in the direct parent Master page (Works) -->
Body content 1
</asp:Content>
<asp:Content ID="Body2Content ContentPlaceHolderID="Body2" runat="server">
<!-- Placed in the direct parent Master page (Works) -->
Body content 2
</asp:Content>

ASP.NET MVC Using Multiple user controls on a single .aspx(view)

I am getting this following error , when i am tring to having two user controls in one page.
The model item passed into the dictionary is of type 'System.Linq.EnumerableQuery1[Data.EventLog]' but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[Data.Notes]'.
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Test
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Test</h2>
<% Html.RenderPartial("~/Views/Shared/UserControl/Tracking.ascx"); %>
<% Html.RenderPartial("~/Views/Shared/UserControl/Notes.ascx"); %>
</asp:Content>
Your Notes.ascx control is strongly-typed, but you are not passing a model in your call to RenderPartial. Hence, the model for the page is passed instead, which is the wrong type for the user control. You need to pass a model in your call to RenderPartial.
For example, if the event log page model has a property called NotesModel:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyNamespace.EventLogModel>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Test
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Test</h2>
<% Html.RenderPartial("~/Views/Shared/UserControl/Tracking.ascx"); %>
<% Html.RenderPartial("~/Views/Shared/UserControl/Notes.ascx", Model.NotesModel); %>
</asp:Content>
Note that I've:
Changed the Inherits bit of the #Page directive to specify the model type and,
Added the model argument to RenderPartial.
You would of course need to populate Model.NotesModel in your controller. If it's null you'll see the same bug you presently see.

How can I automatically refresh a partial view?

I have a simple view:
<%# Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Administration
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Indexer stats</h2>
<div id="Stats">
<% Html.RenderPartial("IndexerStats", CmsModels.Utilities.BackgroundIndexer.Default); %>
</div>
</asp:Content>
How can I automatically refresh the Partial View "IndexStats" every 10 seconds?
I have found this code, but it doesn't compile with my version of MVC (2 RC).
Damn it, you spend ages looking for an answer, ask the question and then find the answer imediately afterwards.
Revised code is:
Indexer stats
<script src="<%=Url.Content("~/Scripts/jquery-1.3.2.min.js")%>" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
setInterval(function() {
$.get('<%=Url.Action("IndexerStats")%>', {}, function(view) {
$("div#IndexerStats").html(view);
})
}, 5000);
}); </script>
<div id="IndexerStats">
<% Html.RenderPartial("IndexerStats"); %>
</div>
</asp:Content>
However I am open to better ideas, or Html helpers.

Resources