如何从Controller.cs中的View中检索数据

时间:2016-02-10 20:20:32

标签: javascript c# controller sitecore sitecore8

这是我的controller.cs(使用Sitecore 8.0)

 public class LocationCardController : ComponentsController
    {
        public ActionResult LocationCardControl()
        {
            GetLocationProperty();



            var model = GetDatasource<LocationCard>();
            // Create a new object to represent the center we are searching from
            var mapCenterCoordinates = new LatLng(model.Location.Latitude, model.Location.Longitude);
            model.Location.Distance = Distance.HaversineDistance(mapCenterCoordinates, model.Location.Coordinate, Distance.DistanceUnit.Miles);
            if (model == null) return null;

            return View(model);
        }

        static void GetLocationProperty()
        {
            GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();

            watcher.TryStart(false, TimeSpan.FromMilliseconds(1000));
            GeoCoordinate coord = watcher.Position.Location;

        }
    }

我想要得到的是当前位置(纬度和长度)要插入&#34; mapCenterCoordinates&#34;变量,显然我必须使用&#34; geolocation&#34;这是javascript,但我不知道如何访问&#34; geolocation&#34; PARMS。

var mapCenterCoordinates = new LatLng(model.Location.Latitude, model.Location.Longitude);
            model.Location.Distance = Distance.HaversineDistance(mapCenterCoordinates, model.Location.Coordinate, Distance.DistanceUnit.Miles);

0 个答案:

没有答案