【问题标题】:Redirect to Link from Link saved in database从保存在数据库中的链接重定向到链接
【发布时间】:2017-12-11 19:15:57
【问题描述】:

我正在用 MVC 开发一个 Web 应用程序。 我在数据库中添加了一个链接例如:“www.google.com”,我希望用户在点击时重定向到 Google。

我尝试了很多方法,但将控制器放在地址栏中 "eg:http://localhost:/Home/www.google.com"

查看代码

<table class="table" style="margin-top:10px;">
<tr>
    <th>
        Sr. No.
    </th>
    <th>
        Name
    </th>
    <th>
        Details
    </th>
    <th>
        Status
    </th>
    <th>
        Tracking No.
    </th>
    <th>
        Tack Order
    </th>
    <th>
        Ordered On
    </th>
</tr>

@{int row = 0;} @foreach (var item in Model) { if (item.PaymentSuccessfull == true) {
<tr>
    <td>
        @(row += 1)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.DeliveryDetail.FirstName)
    </td>
    <td>
        <a href="/Home/OrderDetails?orderId=@item.Id" orderid="1">Order Details</a>
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Status)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.TrackingId)
    </td>
    <td>
        //Here I want user to redirect to Google on click
        <a href="@Html.DisplayFor(modelItem => item.TrackingURL)" target="_blank">Track</a>
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.DateTime)
    </td>
</tr>
} }

感谢您的帮助。 提前致谢。

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 asp.net-mvc-3 model-view-controller hyperlink


    【解决方案1】:

    您必须将协议与 URL 的其余部分一起存储。

    所以:

    www.google.com

    变成:

    http://www.google.com

    【讨论】:

    • @scgough...非常感谢您的帮助。效果非常好。
    猜你喜欢
    • 1970-01-01
    • 2021-10-14
    • 2017-10-10
    • 2016-02-11
    • 2016-08-28
    • 1970-01-01
    • 2014-08-17
    • 2015-07-18
    • 1970-01-01
    相关资源
    最近更新 更多