使用MVC 3 ViewBag来动态改变图像 [英] Use MVC 3 ViewBag to dynamically change an image

查看:369
本文介绍了使用MVC 3 ViewBag来动态改变图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的MVC 3,并还在学习。我目前正在建立一个静态的第2页网站里面有两个页面上不同的形象,但都位于同一个地方。有人告诉我,我可以使用ViewBag取决于我是什么页面上这一形象改变,但是我没有得到一个线索从哪里开始应用该到我的网站。

I'm new to MVC 3 and still learning. I'm currently building a static 2 page website which has a different image on both pages but are located in the same place. I have been told that I can use the ViewBag to change this image depending on what page I am on, however I have not got a clue where to begin with applying this to my website.

任何帮助将大大AP preciated。感谢您的时间。

Any help will be greatly appreciated. Thank You for your time.

推荐答案

在您的控制器的操作方法,请ViewBag或ViewData的这样

On your controller's Action method,make ViewBag or ViewData like this

ViewBag.Imagename="nameofimage";

ViewData["img"]="nameofimage";

在你看来,你可以这样img标签

On your view, you can make img tag like this

<img src="@ViewBag.Imagename">

如果您已经创建的ViewData

<img src="@ViewData["img"]">

这篇关于使用MVC 3 ViewBag来动态改变图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆