在mvccontrib网格中组成外部锚标签 [英] composing external anchor tags in mvccontrib grid

查看:66
本文介绍了在mvccontrib网格中组成外部锚标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用MVCCONTRIB网格进行数据显示,我遇到以下问题。



我想显示外部锚标签 - 例如Google地图作为列数据显示的一部分。



以下代码有效,没有网格:

Hi,

I'm using MVCCONTRIB grid for data display and I'm having difficulty with the following.

I want to display external anchor tags to - for example Google maps as part of column data display.

The below code works, without grid:

<tbody>
            @foreach (var processedShipment in Model)
            {
                <tr>
                    <td>@OriginCity - @OriginState</td>
                    <td>@DestinationCity -@DestinationState</td>
                    <td>@string.Format("{0:0.00 Miles}", @MilesToGO)</td>
                    <td>
                        
<a href="http://maps.google.com/maps?saddr=@OriginCity+@OriginState&daddr=@DestinationCity+
@DestinationState" target="_blank">MapIt</a>

                    </td>
                </tr>
            }
        </tbody>





如你所见,我在Anchor Tag中使用模型值(请忽略anc中的语法错误hor标签,因为我已经删除了键值 - 但它可以根据需要工作。



我的问题是我想在MVCCONTRIB网格中组合上述数据。 />
我有以下不起作用的代码:



As you can see, i'm using model values in Anchor Tag (please ignore syntax errors in anchor tag, as I've deleted key values - but it works as required.

My issue is that I want to compose the above data in MVCCONTRIB grid.
I have the following code that is NOT working:

 @Html.Grid(Model).Columns(column =>
    {
        column.For(m => m.OriginCity + "-" + m.OriginState).Named("Origin");
        column.For(m => m.DestinationCity + "-" + m.DestinationState).Named("Destination");
       
        // Would like to compose an anchor tag here for the google link with saddr and daddr 
        // attributes. For example
       
        column.For(m => <a href="http://maps.google.com/maps? saddr=@OriginCity+@OriginState&daddr=@DestinationCity+
@DestinationState" target="_blank">MapIt</a>
).DoNotEncode()    }).Sort((GridSortOptions)ViewData["sort"]).Attributes(@class => "mvctable");





任何人都可以告诉我我做错了什么。 (mvc网格锚标签不起作用)。



提前谢谢。



Can anyone help by telling me what i'm doing wrong. (The mvc grid anchor tag does not work).

Thanks in advance.

推荐答案

抱歉已经回答了我自己的问题,但是通过以下方式解决了这个问题。



工作代码:



Sorry to have answered my own question, but figured it out in the following way.

Working Code:

@Html.Grid(Model).Columns(column =>
    {
        column.For(m => m.OriginCity + "-" + m.OriginState).Named("Origin");
        column.For(m => m.DestinationCity + "-" + m.DestinationState).Named("Destination");
        column.For(m => string.Format("<a href="\"http://maps.google.com/maps?saddr={0}+{1}&daddr={2}+{3}\"" target="\"_blank\"">ShowMap</a>", 
            m.OriginCity, m.OriginState, m.DestinationCity, m.DestinationState)).Named("Show Map").Encode(false);
    }).Sort((GridSortOptions)ViewData["sort"]).Attributes(@class => "mysummarytable")





注意事项:

1.使用string.Format()用占位符组成锚标签。

2.使用Encode(false)发出正确的html



看起来很有趣的东西:

我对使用占位符持怀疑态度他们之间有空格的城市名称不会被goolgle正确使用。

但事实证明,谷歌采用上面的代码,城市名称有空格:

For例如:Origin - Sioux Falls,South Daktoa,Destincation = Flint,Michigan



Things to note:
1. using string.Format() to compose anchor tag with place holders.
2. Using Encode(false) to emit proper html

Things that seem interesting:
I was skeptical about using place holders as I thought city names that have spaces between them would not be taken by goolgle properly.
But as it turns out, google takes the above code with the city names having space:
For example: Origin - Sioux Falls, South Daktoa, Destincation = Flint, Michigan


这篇关于在mvccontrib网格中组成外部锚标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆