0

I have tried different syntax as belows.

  1. "<img src='../Images/Live news/Actions-arrow-right-icon.png' />" ;

  2. <img src="<%= Url.Content("~/Images/Live news/Actions-arrow-right-icon.png") %>"

I want to add image through controller not view so is these syntex are correct?

This is my full code

 dt = Users.Get_Livenews(0, true, "GActive");
 for (int i = 0; i < dt.Rows.Count; i++) 
 { 
  objExercise = new HomeModel();
  objExercise.livenews = Convert.ToString(dt.Rows[i]["livenews_headline"].ToString()) + "<img src='../Images/Live news/Actions-arrow-right-icon.png' />" ; 
  Horizontal.Add(objExercise); 
 }
13
  • not able to understand the question??? Commented Aug 14, 2014 at 7:52
  • I want to add image threw controller so i have tried the code above Commented Aug 14, 2014 at 7:53
  • dt = Users.Get_Livenews(0, true, "GActive"); for (int i = 0; i < dt.Rows.Count; i++) { objExercise = new HomeModel(); objExercise.livenews = Convert.ToString(dt.Rows[i]["livenews_headline"].ToString()) + "<img src='../Images/Live news/Actions-arrow-right-icon.png' />" ; Horizontal.Add(objExercise); } Commented Aug 14, 2014 at 7:55
  • This is my full code Commented Aug 14, 2014 at 7:55
  • 2
    Adding html mark-up in your controller is a very bad idea. Why are you not wanting to just add it in the View? Commented Aug 14, 2014 at 8:36

1 Answer 1

1

You should get the list of image paths from controller and then iterate the this list at View level. Means dynamically create images for each image path you iterate.

If your view is strongly-typed and controller returns view with model or say list object then using for or foreach loop, you can prepare table or whatever you need.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.