0

I am new to ASP/MVC and as part of that started learning using a simple app.

I have a collection of objects as below in the controller

    public ActionResult loadimage(String FQDN, String trange)
        {
            List<geo_crd> Geo_crd = new List<geo_crd>();

              //more logic


foreach (ToDoItem T in query1)
            {

                IEnumerable<GeoItem> query2 = (from b in db1.GeoItems
                                               where b.DNS_server_address == T.DNS_server_address
                                               select b);
                foreach (GeoItem X in query2)
                {

                    Geo_crd.Add(new geo_crd(X.DNS_latitude, X.DNS_longitude, 1));
                }

            }


            return View(Geo_crd);
        }

Geo_crd is in models as follows

namespace ToDoApp.Models
{
        public class geo_crd 
    {

        private Decimal _geo_lat;
        private Decimal _geo_long;
        private int _status_flag;

        public geo_crd(Decimal x, Decimal y, int z)
        {
            _geo_lat = x;
            _geo_long = y;
            _status_flag = z;
        }

        public Decimal geo_lat
        {
            get { return _geo_lat; }
            set { _geo_lat = value; }
        }

        public Decimal geo_long
        {
            get { return _geo_long; }
            set { _geo_long = value; }
        }

        public int status_flag
        {
            get { return _status_flag; }
            set { _status_flag = value; }
        }


    }
}

I am receiving in the views as follows

@model IEnumerable <ToDoApp.Models.geo_crd>
// more code here 
<script type="text/javascript"> 

    @foreach (var item in Model){ 
            <spam><li> @item.geo_lat </li></spam>
            <span> <li> AddLocationPin(@item.geo_lat, @item.geo_long, null, 'place 1');</li> </span> 
           } 

  </script>

the issue I am having is , the server is not sending the AddlocatioPin , it is just ignoring it I guess.

am i doing something really stupid ? please help

1 Answer 1

1

You should not wrap html tags with script. Start and end tags, also their order must match in html. Also you should read more about HTML ul tag

Correct view would be

@model IEnumerable <ToDoApp.Models.geo_crd>
//more code here 
<ul>
   @foreach (var item in Model)
   { 
       <li><span>@item.geo_lat </span></li>
       <li><span>AddLocationPin(@item.geo_lat, @item.geo_long, null, 'place 1'); </span> </li>
   } 
</ul>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @archil, but for some reason it is still not passing the AddLocationPin when the client view is created and sent. Am i missing something too basic here ?
that issue was html tags within script. Otherwise the solution worked. so accepting it as an answer. what worked is as below

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.