I am new to MVC3
DB has a table called users (id,name,username,lat,lon). I do not have access to the database.
I created entity model using the above table. Then, I created a SearchController and Search View. On the index page I display the list of all users. Also, I created a form on the page that searches the table using the username. After clicking on the details link I show the details page where I display the user’s details.
Now I need to display other users that are within a mile of the selected user. I already have the sql query to get the list of other users that are within a mile of the selected user (This is a sql query). I need to show this list on Details page.
I created a custom class model.
public class SearchDetailsViewModel
{
public decimal id { get; set; }
public string name { get; set; }
public string username { get; set; }
public Nullable<decimal> lat { get; set; }
public Nullable<decimal> lon { get; set; }
public string profile_img_url { get; set; }
public IQueryable<user> usersWithinAMile { get; set; }
}
I am not sure if this is the right approach. Also, I do not know how I would intialize this class.
Any help or suggestion is really appreciated.
Yes, you are on the right track, you get the data from your SQL into the class, and then to the view, in the ActionResult, like this:
Then on your view itself you would do something like this: