Insert a link to a db field mvc 5

放肆的年华 提交于 2019-12-11 18:28:42

问题


I have a field to my db which is external link and one that is a file. I need to display these fields to my view. I have this code where I call my data.

@Html.DisplayFor(model => model.announcement_Link)

and for the file

@Html.DisplayFor(model => model.announcement_Uploaded_File)

It brings the url and the file name . How can I make the 1st to be a link and the second to be linked to the file and to be downloaded? thank you


回答1:


In Database :

1. For A Link:

eg SQL:

update AnnouncementTable set announcement_Link='http://www.example.com/Announcement/All'
where ID=123

2. For A Downloadable Link: (Note: saving uploaded file link with filename in column like:)

update AnnouncementTable set announcement_Uploaded_File='http://www.example.com/Announcement/
download/filename' where ID=123

In asp mvc view

1. For A Link:

<a href="@model.announcement_Link">View</a>

2. For A Downloadable Link:

<a href="@model.announcement_Uploaded_File">View</a>

hope this helps.



来源:https://stackoverflow.com/questions/32904382/insert-a-link-to-a-db-field-mvc-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!