I am trying to implement the same tree slide in my MVC3 application, and I'm not quite sure if I am doing this correctly:
Index Page:
<script type="text/javascript"> $(document).ready(function () { $('#slider a').click(function () { history.pushState({ path: this.path }, '', this.href); $.get(this.href, function (data) { $('#slider').slideTo(data); }); return false; }); }); </script> @{Html.RenderAction("MainTableTracker", "Release", new { releaseId = Model });}
Partial view of MainTableTracker:
<script type="text/javascript"> $(document).ready(function () { $('#slider a').click(function () { history.pushState({ path: this.path }, '', this.href); $.get(this.href, function (data) { $('#slider').slideTo(data); }); return false; }); }); </script> <div id="slider"> @Html.RouteLink(Model.Brand.Name, "Brand", new { BrandId = Model.Brand.Id }) / <ul> <li><a href="#">Overview</a></li> @foreach(var model in Model.ModelExts) { <li>@Html.RouteLink(model.Model.Name, new { modelId = model.Model.Id })</li> } </ul> </div>
Partial view of VersionTable version:
<script type="text/javascript"> $(document).ready(function () { $('#slider a').click(function () { history.pushState({ path: this.path }, '', this.href); $.get(this.href, function (data) { $('#slider').slideTo(data); }); return false; }); }); </script> <div id="slider"> @Html.RouteLink(Model.Brand.Name, "Brand", new { BrandId = Model.Brand.Id }) / @Html.RouteLink(Model.Name, "Model", new { modelId = Model.Id }) / <ul> <li><a href="#">Overview</a></li> @foreach(var model in Model.Brand.Model) { <li>@Html.RouteLink(model.Name, new { modelId = model.Id })</li> } </ul> <div class="versionWraper"> @foreach(var version in Model.Version) { <div> @version.Name </div> } </div> </div>
This works, however I'm sure that I am doing it wrong, I assume that I should not have 3 different views, each time copying the code of the parent view.
I am wondering if I should have only one view model and one action, and let the view decide what to show each time? But I donβt really like to use only one action to display different types of data (Release, Brand and Feature).
In addition, the layout has:
$(window).bind('popstate', function (e) { $.get(e.originalEvent.state.path, function (data) { $('#slider').slideTo(data); }); });
This works, but when I get back to the Brand level, it will reload all my scripts (being that this View is not partial for the standard).
Is there a better way to implement this?
thanks