There are plenty of ways of passing data from a controller to a view. What is not clear is if you are trying to submit data from a view to the controller, then redirect to a different view and still maintain that same data so I'll give you some options.
1) Showing data from your controller into your view
public class HomeController : Controller
{
public ActionResult Index()
{
var model = new IndexModel();
model.Username = "dwimbley";
return View(model);
}
}
In your view you'd have
@model IndexModel
@Model.Username
Which would display dwimbley
This is considered a strongly typed view. I prefer this over other options as I think handling everything via viewbag or tempdata creates a nightmare if you have other devs on your team.
2) Lets say you've submitted a form to an action in a controller. Thant from that POST action you want to display something onto a different view, which i think might be what you are asking.
public class HomeController : Controller
{
public ActionResult Index()
{
TempData["username"] = "dwimbley";
return RedirectToAction("About");
}
public ActionResult About()
{
return View();
}
}
Since index action redirects to about. The only view that matters is About.cshtml. Also, unlike the above example, you don't need a model since you are using tempdata.
@TempData["username"]
One suggestion here. If you are trying to store an object as tempdata and then casting it back to the object type it should be in your view, you are breaking the principles of MVC. I highly recommend you use the strongly typed view route and only utilize TempData/ViewBag/ViewData as exceptions for items that don't fit into your views model.