在这里,我试图在 mvc 中制作一个动态且可编辑的布局页面。在我的布局页面中,我有一个徽标(目前是硬编码的)。我正在实现一个功能,以便任何用户都可以通过上传自己的徽标来更改该徽标。该徽标的路径存储在数据库中。例如,如果这是我现在的徽标:
<img alt="" src="~/Images/W_logo.png" style="border-style: none;" width="115px" height="60px" />
我希望它是这样的:
<img alt="" src="@item.logo" style="border-style: none;" width="115px" height="60px" />
其中“logo”是我在模型中传递的参数。
或者
<img alt="" src="@ViewData["logopath']" style="border-style: none;" width="115px" height="60px" />
此外,如果我使用控制器来存储值,我该如何制作它,以便它在每次应用程序启动时运行。例如这是我的控制器:
public ActionResult layoutChange()
{
--recover path from database--
ViewData["logopath"]=path from the database;
return View(); -- Here the view is the layout page
}
任何帮助将不胜感激。谢谢你。