---
title: "How to pass data from a controller to a Razor view in ASP.NET Core?"  
description: "How to pass data from a controller to a Razor view in ASP.NET Core?"  
author: "Sandra Emily"  
published: 2023-10-20  
updated: 2023-10-25  
canonical: https://www.mindstick.com/forum/160232/how-to-pass-data-from-a-controller-to-a-razor-view-in-asp-dot-net-core  
category: ".net core"  
tags: ["asp.net core", ".net core", "razor view"]  
reading_time: 2 minutes  

---

# How to pass data from a controller to a Razor view in ASP.NET Core?

How to [pass data](https://www.mindstick.com/forum/351/how-to-pass-data-from-controller-to-ascx-page) from a [controller](https://www.mindstick.com/blog/273/passing-values-from-controller-to-view-in-asp-dot-net-mvc) to a [Razor](https://www.mindstick.com/articles/12002/asp-dot-net-mvc5-razor-with-jquery) [view in ASP.NET](https://www.mindstick.com/forum/33955/how-to-create-a-partial-view-in-asp-dot-net-mvc-4) Core?

## Replies

### Reply by Aryan Kumar

In [ASP.NET Core](https://www.mindstick.com/articles/12946/get-started-with-asp-dot-net-core-mvc-and-visual-studio), passing [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) from a controller to a [Razor view](https://www.mindstick.com/forum/155820/how-to-generate-textbox-control-using-htmlhelper-in-razor-view) is a fundamental part of rendering dynamic content. You can pass data to a view from a controller in several ways, including using ViewBag, ViewData, or a strongly typed model. Here's how to do it using each method:

## 1. Using a Strongly Typed Model:

This is the recommended and most common way to pass data to a Razor view. It provides compile-time type checking and IntelliSense support for your views.

## 2. Using ViewBag:

ViewBag is a dynamic property that allows you to pass data to a view, but it lacks compile-time type checking.

## 3. Using ViewData:

ViewData is similar to ViewBag but requires explicit casting to access the data.

## 4. Using TempData (for Redirects):

TempData is used to store data temporarily for a single HTTP request, typically between actions during a redirect.

Passing data from a controller to a Razor view allows you to dynamically generate content based on the context and requirements of your application. Using a strongly typed model is the recommended approach for maintaining type safety and improving code maintainability. However, ViewBag and ViewData are useful for simpler scenarios or when working with dynamic data.


---

Original Source: https://www.mindstick.com/forum/160232/how-to-pass-data-from-a-controller-to-a-razor-view-in-asp-dot-net-core

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
