Link to home
Start Free TrialLog in
Avatar of mustish1
mustish1

asked on

Error on curly brackets

Can any one please help me in that error  Thanks.

User generated image
using MVCContactBook.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVCContactBook.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            List<ContactModel> contacts = new List<ContactModel>();
            //here MyContactBookiEntities is our datacontext
            using (MyContactBookEntities dc = new MyContactBookEntities())
            {
                var v = (from a in dc.Contacts
                         join b in dc.Countries on a.CountryID equals b.CountryID
                         join c in dc.States on a.StateID equals c.StateID
                         select new ContactModel
                         {
                             ContactID = a.ContactId,
                             FirstName = a.ContactPersonFName,
                             LastName = a.ContactPersonLName,
                             ContactNo1 = a.ContactNo1,
                             ContactNo2 = a.ContactNo2,
                             EmailID = a.EmailID,
                             Country = b.CountryName,
                             State = c.StateName,
                             Address = a.Address,
                             ImagePath = a.ImagePath
                         }).ToList();
                contacts = v;
            }
            return View(contacts);
        }

        public ActionResult Add()
        {
            // fetch country data
            List<Country> AllCountry = new List<Country>();
            List<State> states = new List<State>();
            // Here MyContactBookEntities is DbContext
            using (MyContactBookEntities dc = new MyContactBookEntities())
            {
                AllCountry = dc.Countries.OrderBy(a => a.CountryName).ToList();
                //Not need to fetch states as we dont know which country will user select here
            }

            ViewBag.Country = new SelectList(AllCountry, "CountryID", "CountryName");
            ViewBag.State = new SelectList(states, "StateID", "StateName");

            return View();
        }

        //Add more actions for fetch states from jquery code
        public JsonResult GetStates(int countryID)
        {
            using (MyContactBookEntities dc = new MyContactBookEntities())
            {
                //Off Lazy Loading
                var State = {from a in dc.States 
                             where a.CountryID.Equals(countryID)
                             orderby a.StateName 
                             select a).ToList();
                return new JsonResult { Data = State, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
            }
        }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Karrtik Iyer
Karrtik Iyer
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial