In my master pag开发者_如何学Goe I have a menu that uses jquery ui accordion.
What is the best way to specify which item should be active?? the only thing I can think of is
$(document).ready(function() {
$("#accordion").accordion({
collapsible: true,
autoHeight: false,
active:<%=ViewData["active"] %>
});
})
But it seems a little repetitive having to set ViewData["active"] everytime a View is called throughout my whole app... what do you think?
Have you considered putting the accordian in a PartialView? Then you place your code within the PartialView and away from the Master page.
Also you can have a base controller which can set the ViewData for you so now it's in one place.
Edit
It's the same as any other base class. Your controller inherits from Controller
so your base class will need to do the same;
using System.Web.Mvc;
namespace MyAppControllers
{
public class ControllerBase : Controller
{
protected override void Execute(System.Web.Routing.RequestContext requestContext)
{
ViewData["ApplicationName"] = CacheHelper.Get().Name;
base.Execute(requestContext);
}
}
}
Now set your controller class to inherit from the ControllerBase class;
public class HomeController : ControllerBase
I've also implemented a CacheHelper but you can obviously use your own flavour of storing the current value.
精彩评论