Answer the question
In order to leave comments, you need to log in
How to pass variable from controller to view?
Good afternoon. There are variables in the controller
public static int suggestionCount { get; set; } = 3;
public static int symbolCount { get; set; } = 1;
@{
var symbolCount = WebApp.Controllers.HomeController.symbolCount;
var suggestionCount = WebApp.Controllers.HomeController.suggestionCount;
}
Answer the question
In order to leave comments, you need to log in
You need to pass the model to the view. Unfortunately, a quick google only gave a link to metanit . This topic is more or less described there, but I do not recommend using it at all
If the values of the variables are small, you can also call
@ViewBag.suggestionCount
@ViewBag.symbolCount through the ViewBag
in the controller
ViewBag.suggestionCount = 3
ViewBag.symbolCount = 1
and in the view
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question