ASP.NET MVC – dynamic Model from a View
using System.Dynamic; public ActionResult Index() { dynamic model = null; model = new User() { ID = 1, Name = "User Name", PostTitle = "Boss", Department = "Boss" }; return View(model); } |
@model dynamic … … @if (Model.GetType() == typeof(… …)) { < div class="row">@(Model.ID)< /div> < div class="row">@(Model.Name)< /div> < div class="row">@(Model.PostTitle)< /div> < div class="row">@(Model.Department)< /div> } else if (Model.GetType() == typeof(… …)) { … … The Other Combination of HTML Layout Presentation. } else { < div class="row">Invalid Model</div> } |