[英]How to load Subgurim GMap object in razor(MVC3/4)
I'm using ASP.NET MVC 4 and I'm trying to load a Google Map on my page. 我正在使用ASP.NET MVC 4,并且试图在页面上加载Google Map。
I'm using Subgurim lib and already have the map object, but I don't know how to load it into the page. 我正在使用Subgurim lib,并且已经有了map对象,但是我不知道如何将其加载到页面中。
Here's what I got so far: 这是到目前为止我得到的:
@model Subgurim.Controles.GMap
@{
ViewBag.Title = "Pesquisa Carona";
}
<h2>PesquisaCarona</h2>
<h4>Diga o endereço</h4>
<input type="text" name="txEndereco" />
<input type="submit" />
<cc1:GMap ID="googleMap" runat="server" /> <!-- This doesnt work!!!--!>
I know that normally I would add the map accessing it directly like: 我知道通常我会添加直接访问它的地图,例如:
For the serverside: 对于服务器端:
GMap1.addGMarker(oMarker);
And for the page: 对于页面:
<cc1:GMap ID="GMap1" runat="server" Height="300px" Width="300px" />
But with MVC I can't do that. 但是使用MVC我无法做到这一点。
Cheers! 干杯!
I was able to the the basic example to work using .NET 4.5, MVC 5 (razor), GMaps 4.1.0.6, and Visual Studio 2013 by rendering an ascx user control as a partial in the cshtml. 通过将ascx用户控件呈现为cshtml的一部分,我能够使用.NET 4.5,MVC 5(剃刀),GMaps 4.1.0.6和Visual Studio 2013的基本示例。 Here is what I did to get it to work:
这是我为使其工作而要做的事情:
In the ascx: 在ascx中:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Gmap.ascx.cs" Inherits="YourApp.Views.Gmap" %> <%@ Register Assembly="GMaps" Namespace="Subgurim.Controles" TagPrefix="gmaps" %> <form id="form1" runat="server"> <gmaps:GMap ID="GMap1" runat="server" Width="500px" Height="250px" EnableViewState="False" /> </form>
In the ascx.cs: 在ascx.cs中:
namespace YourAPP.Views { using System; using System.Drawing; using System.Web.Mvc; public partial class Gmap : ViewUserControl { protected void Page_Load(object sender, EventArgs e) { GMap1.enableDragging = false; GMap1.Language = "en"; GMap1.BackColor = Color.White; GMap1.Key = "YOUR GOOGLE KEY"; GMap1.CommercialKey="YOUR COMMERCIAL KEY"; } } }
In the cshtml: 在cshtml中:
@Html.Partial("Gmap")
@ Html.Partial(“ Gmap”)
** A couple of things to note: **需要注意的几件事:
The form tag in the ascx is required it won't work without it. ascx中的form标记是必需的,没有它就无法使用。
The control needs to inherit from ViewUserControl instead of UserControl to work with razor. 该控件需要继承自ViewUserControl而不是UserControl才能使用剃刀。
Make sure you have your keys for the control (Google, Commercial). 确保您具有控件的键(Google,Commercial)。 See the control site for details on those.
有关详细信息,请参见控制站点。
If you didn't put the control in the same folder as your cshtml you will need to adjust the path given to the Partial helper. 如果未将控件与cshtml放在同一文件夹中,则需要调整提供给Partial helper的路径。
Thank you to: 谢谢至:
I hope this helps - Cheers, 我希望这会有所帮助-干杯,
Anker 安克尔
I've got the same problem. 我有同样的问题。
On my project (made with MVC3) I've added a partial view in aspx engine (the rest of my website is with razor). 在我的项目(使用MVC3制作)中,我在aspx引擎中添加了部分视图(我的网站的其余部分使用剃刀)。 I followed the subgurim tutorial site.
我关注了subgurim教程站点。 Then I added the google api key but I get a gray rectangle even if everything seems ok!
然后我添加了google api键,但是即使一切似乎正常,我也会得到一个灰色矩形! Then I found this post on google: http://it.googlemaps.subgurim.net/Foro/general-discussions-perm5956-5963.aspx
然后我在Google上找到了这篇文章: http : //it.googlemaps.subgurim.net/Foro/general-discussions-perm5956-5963.aspx
:( :(
I'm one of the developers of the project and we are working on a new version suitable for MVC (Razor or other view engine of choice). 我是该项目的开发人员之一,我们正在开发适用于MVC(Razor或其他选择的视图引擎)的新版本。 I'll update this response when it's ready for production.
准备生产时,我将更新此响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.