I am trying to use a variable that I set in my controller to be the src inside of an img tag. I copied the string in directly and it worked so I know my path is correct. However, I am having trouble figuring out how to place the variable I create into the img tag.
Here is my controller:
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace dojodachi.Controllers
{
public class HomeController : Controller
{
// GET: /Home/
[HttpGet]
[Route("")]
public IActionResult Index()
{
ViewData["Tree"] = "~/images/regular_tree.jpeg";
return View();
}
}
}
Here is my cshtml file
<div id = wrapper>
<p>Fullness: Happiness: Meals: Energy</p>
<div id = inside>
<img src="@ViewData['Tree']" alt="Regular Tree"> //How do I place my variable in this img tag?
<p></p>
</div>
</div>