views:

18

answers:

1

I have list of cities on my site, this list placed in Site.Master and look like:

<a id="<%= selectedCity.CityId %>"><%= selectedCity.Name %></a>
<ul>
    ...
    <li id="<%= city.CityId %>" >
    <%= Html.ActionLink(city.Name,"ChangeCity",new{ newCityId = city.CityId })%>
    </li>
    ...
</ul>

Next, all my controller are based from BaseController, it contain next code:

public int CityId {get;set;}
protected override void OnActionExecuting(ActionExecutingContext filterContext){
    if (filterContext.ActionDescriptor.ActionName.ToLower() != "changecity"){
        this.CityId = Convert.ToInt32(Request.Cookies["SiteCityId"]);  
        var city = LoadCity(this.CityId);
        var cities = LoadAllCities(); 
        CitiesModel model = new CitiesModel() { selectedCity=city, allCities=cities};
        ViewData["citiesModel"] = city;
    }
    else{
       Response.Cookies["SiteCityId"]=filterContext.ActionParameters["newCityId"];
    }   
}

In all my controllers I was add next action:

[HttpGet]
public ActionResult ChangeCity(string newCityId)
{
    return RedirectToAction(this.MyDefaultAction);
}

Main question: this schema not so good work. In IE8 sometimes I cant change current city use links like next:

http://www.mysite.com/home/changecity/?newCityId=3

And what you think about this schema at all? May be you use other methods for create functionality?

A: 

Interesting idea; it might be better served by using the new Html.Action() feature in MVC 2, where you can, in your view, call <%= Html.Action("ChangeCity", "Common") %> to display the change city action in a common controller, and in there is the logic to do this, rather than doing it for every action.

HTH.

Brian