如何将动态数据从视图传递到控制器 [英] how to pass the dynamic data from view to the controller

查看:85
本文介绍了如何将动态数据从视图传递到控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试从数据库动态加载图像,为此我使用了


I am trying to load the image dynamically from the database,for that i used like

<img src='@Url.Action("GetImage/${ID}", "Home")'  alt = "${name} image" />
but it not reflecting to the controller,but if i put statically like
<img src='@Url.Action("GetImage/1", "Home")'  alt = "${name} image" />


然后将其发送到控制器并显示图像.

我的控制器代码是:


then it is going to the controller and it is displaying image .

my controller code is:

public ActionResult GetImage(int id)
        {
            var imgquery = (from img in dbContext.Listdetails where img.ID == id 
                            select new
                            {
                                Image = img.Image
                            }).FirstOrDefault();
            {
                System.IO.MemoryStream outStream = new System.IO.MemoryStream();
                byte[] Image = imgquery.Image;
                return File(Image, "Image/jpg");
            }
        }


任何建议..


Any suggestions..

推荐答案

{ID},"主页)' alt
{ID}", "Home")' alt = "


{name}图片" / > 但是它没有反映到控制器,但是如果我静态地喜欢 < img =' alt ="
{name} image" /> but it not reflecting to the controller,but if i put statically like <img src='@Url.Action("GetImage/1", "Home")' alt = "


{name}图片" / >>
{name} image" />


然后将其发送到控制器并显示图像.

我的控制器代码是:


then it is going to the controller and it is displaying image .

my controller code is:

public ActionResult GetImage(int id)
        {
            var imgquery = (from img in dbContext.Listdetails where img.ID == id 
                            select new
                            {
                                Image = img.Image
                            }).FirstOrDefault();
            {
                System.IO.MemoryStream outStream = new System.IO.MemoryStream();
                byte[] Image = imgquery.Image;
                return File(Image, "Image/jpg");
            }
        }


有什么建议.


Any suggestions..


这篇关于如何将动态数据从视图传递到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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