Note that there are some explanatory texts on larger screens.

plurals
  1. POViewDataFactory and strongly typed master pages
    text
    copied!<p>Im trying to get my strongly typed master page to work in my ASP MVC 2.0 application. I have come far with the help of these two posts:</p> <p><a href="https://stackoverflow.com/questions/78548/passing-data-to-master-page-in-asp-net-mvc/746011#746011">Passing data to Master Page in ASP.NET MVC</a></p> <p><a href="http://www.matthewlowrance.com/matthewlowrance/post/2009/11/11/Strongly-Typed-ASPNet-MVC-Master-Pages.aspx" rel="nofollow noreferrer">Strongly Typed ASP.Net MVC Master Pages</a></p> <p>Problem is that im not sure how to get that ViewDataFactory code to work, this is my code:</p> <p><b>BaseController.cs</b></p> <pre><code>public class BaseController : Controller { private IPageRepository _repPage; public BaseController(IPageRepository repPage) { _repPage = repPage; } protected T CreateViewData&lt;T&gt;() where T : MasterViewData, new() { IViewDataFactory factory = new ViewDataFactory(); IEnumerable&lt;Page&gt; pages = _repPage.GetAllPages(); return factory.Create&lt;T&gt;(pages); } } </code></pre> <p><b>HomeController.cs</b></p> <pre><code>public class HomeController : BaseController { public ActionResult Index() { HomeViewData viewData = CreateViewData&lt;HomeViewData&gt;(); viewData.Name = "Test"; return View("Index", viewData); } public ActionResult About() { return View(); } } </code></pre> <p><b>ViewDataFactory.cs</b></p> <pre><code>public interface IViewDataFactory { T Create&lt;T&gt;(IEnumerable&lt;Page&gt; pages) where T : MasterViewData, new() } public class ViewDataFactory : IViewDataFactory { public ViewDataFactory() { } } </code></pre> <p><b>HomeViewData.cs</b></p> <pre><code>public class HomeViewData : MasterViewData { public string Name { get; set; } } </code></pre> <p><b>MasterViewData</b></p> <pre><code>public class MasterViewData { public IEnumerable&lt;Page&gt; Pages { get; set; } } </code></pre> <p>When I build the solution I get the follwing build error:</p> <pre><code>"; expected" in ViewDataFactory.cs </code></pre> <p>Which points to the code snippet:</p> <pre><code>T Create&lt;T&gt;(IEnumerable&lt;Page&gt; pages) where T : MasterViewData, new() </code></pre> <p>I guess im missing something essential, im new to this and any help would be appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload