首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何执行绑定到剃刀文本框的GeoCode计算?

如何执行绑定到剃刀文本框的GeoCode计算?
EN

Stack Overflow用户
提问于 2012-02-17 19:56:02
回答 1查看 274关注 0票数 0

在RazorMVC3中,使用ASP.NET视图引擎,我有一些结合了地址的文本框(如街道、街道nr、邮政编码)。

我想在我有足够的信息(如街道长度> 0,街道长度nr >0等)后调用Bing GeoCode the服务。如果在客户端验证所有的文本框都有足够的信息,然后进行回发(到Controller),这将是很好的。回发后,必须在视图中显示View服务调用的结果(经度/经度)。

如何做到这一点?

EN

回答 1

Stack Overflow用户

发布于 2012-02-17 20:23:53

型号:

代码语言:javascript
运行
复制
public class GeoCodeViewModel
{
    [StringLength(70, MinimumLength = 1)]
    public string Street { get; set; }

    [StringLength(10, MinimumLength = 1)]
    public string PostCode { get; set; }
}

控制器:

代码语言:javascript
运行
复制
public class HomeController : Controller
{
    public ActionResult Index()
    {
        var model = new GeoCodeViewModel();
        return View(model);
    }

    [HttpPost]
    public ActionResult Index(GeoCodeViewModel model)
    {
        if (!ModelState.IsValid)
        {
            // the model is not valid => redisplay the view so that 
            // the user can fix his errors
            return View(model);
        }

        // TODO: at this stage the model is valid => call the web service
        ...
    }
}

查看:

代码语言:javascript
运行
复制
@model GeoCodeViewModel

<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>

@using (Html.BeginForm())
{
    <div>
        @Html.LabelFor(x => x.Street)
        @Html.EditorFor(x => x.Street)
        @Html.ValidationMessageFor(x => x.Street)
    </div>
    <div>
        @Html.LabelFor(x => x.PostCode)
        @Html.EditorFor(x => x.PostCode)
        @Html.ValidationMessageFor(x => x.PostCode)
    </div>
    <p><button type="submit">OK</button></p>
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9327790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档