Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MasterViewData
- {
- public ICollection<string> Navigation { get; set; }
- }
- public class IndexViewData : MasterViewData
- {
- public string Name { get; set; }
- public float Price { get; set; }
- }
- public interface IViewDataFactory
- {
- T Create<T>()
- where T : MasterViewData, new()
- }
- public class ProductController : Controller
- {
- public ProductController(IViewDataFactory viewDataFactory)
- ...
- public ActionResult Index()
- {
- var viewData = viewDataFactory.Create<ProductViewData>();
- viewData.Name = "My product";
- viewData.Price = 9.95;
- return View("Index", viewData);
- }
- }
- public class IndexViewData : MasterViewData
- {
- public string Name { get; set; }
- public float Price { get; set; }
- public SubViewData SubViewData { get; set; }
- }
- <% Html.RenderPartial("Sub", Model.SubViewData); %>
- <script runat="server" type="text/C#">
- protected override void OnLoad(EventArgs e)
- {
- base.OnLoad(e);
- MasterModel = SiteMasterViewData.Get(this.Context);
- }
- protected SiteMasterViewData MasterModel;
- </script>
Add Comment
Please, Sign In to add comment