I have created a ViewUserControl in my ASP.NET MVC 2 project. This ViewUserControl serves as the general page-header for all views in the project.
How can I add a custom property on ViewUserControls, accessible from views using that control?..:
<%@ Register
Src="../Shared/Header.ascx"
TagName="Header"
TagPrefix="uc" %>
<uc:Header
runat="server"
ID="ucHeader"
MenuItemHighlighted="Menuitem.FrontPage" /> <!-- custom property, here -->
Instead of creating user controls ala WebForms way I would suggest you the following:
Create a strongly typed user control
Header.ascx:And then simply include it in your pages:
In my example the user control is strongly typed to
stringbut you could’ve used any custom type.