pass two models to view [duplicate]

You can create special viewmodel that contains both models:

public class CurrencyAndWeatherViewModel
{
   public IEnumerable<Currency> Currencies{get;set;}
   public Weather CurrentWeather {get;set;}
}

and pass it to view.

public ActionResult Index(int year,int month,int day)
{
    var currencies = from r in _db.Currencies
                where r.date == new DateTime(year,month,day)
                select r;
    var weather = ...

    var model = new CurrencyAndWeatherViewModel {Currencies = currencies.ToArray(), CurrentWeather = weather};

    return View(model);
}

Leave a Comment