1
我目前有一个用户控件,用于/地址/编辑和/地址/创建页面。此用户控件只是在它下面的代码提交新的地址系统:有关ASP.NET MVC表单发布场景的问题
<%
using (Html.BeginForm())
{
%>
<table>
<tr>
<td>Street Address</td>
<td>
<%= Html.TextBox("StreetAddress", (ViewData.Model != null) ? ViewData.Model.StreetAddress : "") %>
<%= Html.ValidationMessage("Address.StreetAddress") %>
</td>
</tr>
</table>
<%= Html.SubmitButton() %>
<%
if (ViewData["GeocodeResults"] != null) {
%>
<p>
Google maps found the following addresses that matched the address you entered. Please select
the appropriate address. If none of these addresses are correct, try reentering the address
again and be as specific as possible.
</p>
<ul>
<%
foreach (GeocodeResult geocodeResult in (List<GeocodeResult>)ViewData["GeocodeResults"]) {
%>
<li>
<%= geocodeResult.StreetAddress %>
</li>
<%
}
%>
</ul>
<%
}
%>
<%
}
%>
总结上面的代码,它的作用是在控制器,它查询谷歌地图进行地理编码的地址文本框(即将其变成一组经度/纬度坐标)。当Google地图返回多个结果时,我会将这些结果存储到ViewData [“GeocodeResults”]中,然后向最终用户显示可能的地址。
现在,这对于显示地址工作正常,但我真正想要的是将该列表呈现为超链接列表,以便用户可以单击适当的地址并将该表单与该地址一起提交在文本框中的一个。有没有办法做到这一点?