Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net MVC3中的超链接_Asp.net_Asp.net Mvc_Asp.net Mvc 3_Razor - Fatal编程技术网

Asp.net MVC3中的超链接

Asp.net MVC3中的超链接,asp.net,asp.net-mvc,asp.net-mvc-3,razor,Asp.net,Asp.net Mvc,Asp.net Mvc 3,Razor,我在MVC3剃须刀里有这个。。我想把它做成一个超链接,这样用户就可以点击它了。现在它只是在视图中打印URL的文本。。谢谢你的帮助 <td> @Html.DisplayFor(modelItem => item.WebLink) </td> @DisplayFor(modeleItem=>item.WebLink) 多亏了Richard,这是解决方案 @{ var link = @item.WebLink;

我在MVC3剃须刀里有这个。。我想把它做成一个超链接,这样用户就可以点击它了。现在它只是在视图中打印URL的文本。。谢谢你的帮助

   <td>
        @Html.DisplayFor(modelItem => item.WebLink)
    </td>

@DisplayFor(modeleItem=>item.WebLink)
多亏了Richard,这是解决方案

  @{
       var link = @item.WebLink;
       if (link != null)
       {
           if (!link.StartsWith("http://"))
            { 
               link = "http://"+link;
            }
       }
     }

        <a href="@link">@item.WebLink</a>
@{
var link=@item.WebLink;
如果(链接!=null)
{
如果(!link.StartsWith(“http://”))
{ 
link=“http://”+link;
}
}
}
您只需使用:

<td><a href="@item.WebLink">@item.WebLink</a></td>

假设item是for循环中的变量名。

您只需使用:

<td><a href="@item.WebLink">@item.WebLink</a></td>

假设item是for循环中的变量名。

您应该尝试:

<a href="@item.WebLink">@item.WebLink</a>

好的,根据您的评论,您将需要:

@{
   var link = @item.WebLink;
   if (!link.StartsWith("http://")) { link = "http://"+link; }
}

<a href="@link">@item.WebLink</a>
@{
var link=@item.WebLink;
如果(!link.StartsWith(“http://”)为{link=“http://”+link;}
}
您应该尝试:

<a href="@item.WebLink">@item.WebLink</a>

好的,根据您的评论,您将需要:

@{
   var link = @item.WebLink;
   if (!link.StartsWith("http://")) { link = "http://"+link; }
}

<a href="@link">@item.WebLink</a>
@{
var link=@item.WebLink;
如果(!link.StartsWith(“http://”)为{link=“http://”+link;}
}
这对我很有用:

@{
    string site = "www.google.com";
}

<a href="http://@site"> Go to the site @site </a>
@{
string site=“www.google.com”;
}
这对我很有用:

@{
    string site = "www.google.com";
}

<a href="http://@site"> Go to the site @site </a>
@{
string site=“www.google.com”;
}
将其转换为

简单html

<a href="@item.WebLink">Linkname</a>
我不知道你的链接将以何种形式出现,但是 如果它在home/index jst中,则使用split(“/”)将其拆分,并在razor中使用它

将其转换为

@html.actionlink("@item.WebLink","actionname","controllername")
简单html

<a href="@item.WebLink">Linkname</a>
我不知道你的链接将以何种形式出现,但是
如果它在home/index jst中,则使用split(“/”)将其拆分,并在razor中使用它

,但单击并不会将我带到谷歌URL。。它实际上把我带到了。。我遗漏了什么?好的,现在修复了http问题你遗漏了妄想。。我做了一点修改。。这个效果最好。谢谢你告诉我做这件事的正确方法。我也编辑了原帖@{var link=@item.WebLink;if(link!=null){if(!link.StartsWith(“http:/”){link=“http:/”+link;}}}}}}}但单击并没有将我带到谷歌URL。。它实际上把我带到了。。我遗漏了什么?好的,现在修复了http问题你遗漏了妄想。。我做了一点修改。。这个效果最好。谢谢你告诉我做这件事的正确方法。我也编辑了原帖@{var link=@item.WebLink;if(link!=null){if(!link.StartsWith(“http:/”){link=“http:/”+link;}}}}}}}但单击并没有将我带到谷歌URL。。它实际上把我带到了localhost:2323/Controller/ActionName/www.google.com。。我有什么遗漏吗?——ZVenueBut点击并没有把我带到谷歌网址。。它实际上把我带到了localhost:2323/Controller/ActionName/www.google.com。。我有什么遗漏吗?——兹韦努埃
@html.actionlink("@item.WebLink","actionname","controllername")