Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
**Controler--



    public ActionResult DisplayImage(Users stu)
            {
                List<Users> studs = new List<Users>();
                studs = stu.GetImagesFromDB(stu);

                return View(studs);
            }

Model-

namespace MVC3Test.Models
{

    public class Users
    {
        [Required]
        public HttpPostedFileBase file { get; set; }
        public int lm_id { get; set; }
        public byte[] file_data { get; set; }

        public string Countryid { get; set; }
        public string CountryName { get; set; }
        public List<SelectListItem> CountryList { get; set; }
        public int UserID { get; set; }
        [Required]
        [Display(Name="First name")]

        public string FirstName { get; set; }
        [Required]
        [Display(Name = "Last name")]
        public string LastName { get; set; }
        [Required]
        [Display(Name = "Address")]
        public string Address { get; set; }
        [Required]
        [Display(Name = "Select Gender")]
        public int gender { get; set; }
        [Required]
        [Display(Name = "Email")]
        [StringLength(250)]
        [RegularExpression(@"([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})", ErrorMessage = "Not a valid e-mail address")]
        public string Email { get; set; }






         public List<Users> GetImagesFromDB(Users stud)
         {
             string pstrrc = "sp_getAllImages";
             List<Users> AllImages = new List<Users>();

             List<SqlParameter> arrparam = new List<SqlParameter>();

             SqlParameter param1 = new SqlParameter("@lm_id", SqlDbType.Int);
             param1.Value = stud.lm_id;
             arrparam.Add(param1);

             DataTable dt = Users.SelectStoreProcedure(pstrrc, arrparam);

             foreach (DataRow row in dt.Rows)
             {
                 Users images = new Users();

                 images.lm_id = Convert.ToInt32(row["lm_id"]);
                 images.file_data = (byte[])(row["file_data"]);

                 AllImages.Add(images);
             }
             return AllImages;
         }
    }
}


view-

@model IEnumerable<MVC3Test.Models.Users>

@{
    ViewBag.Title = "DisplayImage";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<!DOCTYPE html>

<html>
<head>
    <title>DisplayImage</title>
</head>
<body>

    <table>
        <tr>
            <th>
                lm_id
            </th>
            <th></th>
        </tr>

    @foreach (var item in Model) {
        <tr>
            <td>
                <img src="@Url.Action("DislpayImage", "Home",new { id =item.lm_id }))" alt="myimage" />

            </td>
        </tr>
    }

    </table>
</body>
</html>
Posted
Updated 27-Jan-14 17:54pm
v2

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900