The difference between the <ViewResult> and ViewResult jobs
2 answers
, ; . , .
, Professional ASP.NET MVC 4
public class PortalController : Controller {
public ActionResult Index(string city) {
NewsService newsService = new NewsService();
WeatherService weatherService = new WeatherService();
SportsService sportsService = new SportsService();
PortalViewModel model = new PortalViewModel {
News = newsService.GetNews(city),
Weather = weatherService.GetWeather(city),
Sports = sportsService.GetScores(city)
};
return View(model);
}
}
, , , , , . 200, 300 400 (), 900 ( ).
, :
public class PortalController : Controller {
public async Task<ActionResult> Index(string city) {
NewsService newsService = new NewsService();
WeatherService weatherService = new WeatherService();
SportsService sportsService = new SportsService();
var newsTask = newsService.GetNewsAsync(city);
var weatherTask = weatherService.GetWeatherAsync(city);
var sportsTask = sportsService.GetScoresAsync(city);
await Task.WhenAll(newsTask, weatherTask, sportsTask);
PortalViewModel model = new PortalViewModel {
News = newsTask.Result,
Weather = weatherTask.Result,
Sports = sportsTask.Result
};
return View(model);
}
}
, , , , . 200, 300 400 , 400 ( ).
+1