C# 访问资源文件中的全局变量
我有一个MVC项目,其中有一个返回url的全局函数。以下是其中之一:C# 访问资源文件中的全局变量,c#,asp.net-mvc,embedded-resource,C#,Asp.net Mvc,Embedded Resource,我有一个MVC项目,其中有一个返回url的全局函数。以下是其中之一: using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Account.Models { public class ApplicationStrings { public static string ApplicationString(){
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Account.Models
{
public class ApplicationStrings
{
public static string ApplicationString(){
return "http://localhost11234/Studentbook";
}
}
}
我有资源文件,我存储的电子邮件正文不同的电子邮件出去。这是一个嵌入式资源
如何从资源文件中的全局函数访问URL
我尝试以下方法,但看不到链接:
<html>
<body>
<br> Student ID : <a href= ApplicationStrings.ApplicationString() + ?id=JD1123>JD1123</a><br>
</body>
</html>
这里JD1123是一个链接,该链接将我带到“ApplicationString.ApplicationString()”,而不是http://localhost11234/Studentbook?id=JD1123“你不能做你想做的事,至少不能直接做。资源字符串是静态项,在访问它们时不会自动更改。因此,基本上,你正从你投入的东西中得到回报。计算机不够聪明,无法知道它应该进行方法调用以使配置字符串卡在其中 相反,您需要编写一段中间代码,在资源字符串中搜索要替换的特定项(可能用或什么标记它们),然后使用Regex.replace插入正确的文本。这是相当微不足道的事情
Student ID : JD1123