I have a issue in Visual Studio 2017. I want to get data from the controller in the Razor file. So the value doesn't exist in the file.
The code and problem is below.
Controller:
public IActionResult Product(int? product)
{
if (product == 0)
{
return RedirectToAction("index", "home");
}
else
{
ViewBag.product = product;
return View();
}
}
scripts:
@section Scripts{
<script>
var pr = @ViewBag.product;
</script>
}
Some links of what I haved tried in order to fix it: question1 question2