0

This is my code in my model, I want to use the variable lat to my view. Is there a way to use it there?

The string has a lat and lng with it. What I want to happen is when the string is selected in the text the lat and lng is selected as well but it will be stored in the variable and I will use it in the view and pass it to the script where it will view it in the google map api.

 public IEnumerable<String> GetStartList()
            {
                //int count = 0;
                var result = new List<String>(10);
                string query = "SELECT PlaceName, Lat, Lng from Places";
                SqlCommand cmd = new SqlCommand(query, con);
                con.Open();
                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var mystring = dr.GetString(0);
                        var lat = dr.GetDouble(1);
                        result.Add(mystring);
                        //result.Add(lat.ToString());
                        //count++;

                    }
                }
                con.Close();
                return result;
            }
3
  • 1
    You could make Lat a property and then using binding in the WPF to bind your control to the Lat property. Commented Sep 25, 2015 at 15:29
  • how can i do that? by using a stored procedure? sorry Im really new to this Commented Sep 25, 2015 at 15:33
  • 1
    Check out my answer to this question. In your case you wouldn't need a converter. You would just save lat to a property and bind that property using XAML stackoverflow.com/questions/32769120/… Commented Sep 25, 2015 at 15:43

2 Answers 2

0

Data queries should be in a separate repository.

However if you are passing back just the two strings add both of them to a parent list

IList<IList> model = new List<IList>();
//code to get lat and result
model.add(result);
model.add(lat);
return View(model);

Then in the View, parse the model using Razor.

@model List<IList>
//... body before using model
@foreach (var lat in model[1]) { ... }
Sign up to request clarification or add additional context in comments.

Comments

0
  • In action

        int model = 0;
        return View(model);
    
  • In View

    @model int @{ //Layout = null; } @if(Model == 0) { //You'r Code }

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.