How to properly encode links to external URL in MVC Razor

前端 未结 5 1902
Happy的楠姐
Happy的楠姐 2021-01-03 21:26

This view suppose to show a list of hyperlinks, each pointing to an external URL. The goal is for the user to click one of these links and have their browser open a new tab

5条回答
  •  天涯浪人
    2021-01-03 22:00

    Two ways :

    1. update the database column with full link:

    eg SQL:

    update ProductTable set LinkColumn='http://www.example.com/Product/Mobiles' where ID=123
    

    In asp mvc view

    View
    

    2. Hardcode the http part and list from model

    View
    

    hope helps someone.

提交回复
热议问题