如何在MVC5 razor视图中嵌入字符串内的链接? [英] How to embed a link inside a string in MVC5 razor view?
问题描述
这可能是一个非常容易回答的问题。但我很困惑如何实施。
我在数据库表中存储了一个字符串。
字符串 - 如果您有任何疑问,请访问我们的支持页面了解更多信息。
我必须使单词 - '支持页面'可点击以便它带我到一个链接。
我将它传递给使用viewbag的视图并将其存储在字符串变量中。
现在正在用htmlhelper标签显示它。
如果你发现它也请忽略dumb.Thanks提前回复。
我尝试过:
It may be a very easy question to answer.But i am puzzled how to implement.
I have stored a string in database table.
String - "If you have any queries, please visit our support page for more information".
I have to make the words - 'support page' clickable such that it takes me to a link.
I am passing this to a view using viewbag and storing it in a string variable.
Right now am displaying it in a htmlhelper label.
Please ignore if you find its too dumb.Thanks in advance for your response.
What I have tried:
@if (ViewBag.validateResult == "true")
{
string message = ViewBag.messageInfo; // string form DB(Table)
@Html.LabelForModel(message, new { @class = " alert alert-success fade in" })
}
推荐答案
您可以将链接的HTML添加到字符串中,并使用 Html.Raw 方法。类似于:
@{
string msg1 = "My Text <a href=\"http://www.google.com\">My link</a>.";
@Html.Raw(msg1)
}
这篇关于如何在MVC5 razor视图中嵌入字符串内的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!