我有一个URL,我想在Razor视图中的锚标记中呈现.我原以为Html.Raw会是你要走的路:
@{
string test = "http://someurl.com/someimage.png?a=1234&b=5678";
}
<div>
<a href="@Html.Raw(test)">Test</a>
</div>
Run Code Online (Sandbox Code Playgroud)
但这不起作用.&符号被编码,HTML呈现为:
<div>
<a href="http://someurl.com/someimage.png?a=1234&b=5678">Test</a>
</div>
Run Code Online (Sandbox Code Playgroud)
奇怪的是,如果我在锚标记之外进行Html.Raw调用,则HTML输出符合预期:
<div>
@Html.Raw(test)
<div>
Run Code Online (Sandbox Code Playgroud)
呈现为:
<div>
http://someurl.com/someimage.png?a=1234&b=5678
</div>
Run Code Online (Sandbox Code Playgroud)
谁能解释为什么会这样?
编辑:
尝试了其他一些事情,发现以下工作符合预期:
<div data-url="@Html.Raw(test)"></div>
Run Code Online (Sandbox Code Playgroud)
输出:
<div data-url="http://someurl.com/someimage.png?a=1234&b=5678"></div>
Run Code Online (Sandbox Code Playgroud)
为了添加更多的上下文,我的目标实际上并不是在锚标记中使用URL,因为href
s可以是HTML编码的并且仍然有用(我只使用锚标记作为示例).相反,我希望在<object> <param>
Flash对象的值标记中使用URL .Flash对象无法正确识别HTML编码的URL,但我无法正确输出原始URL.
我很茫然.是时候打破MVC源代码我猜...
我试图使用mongo.exe --eval命令行开关调用MongoDB javascript片段.从Windows命令行运行时,这可以正常工作,但我想从Powershell脚本调用它,如下所示:
Invoke-Expression "& `"C:\MongoDB\bin\mongo.exe`" localhost:27017/mydb --eval `"db.mydata.update({}, {`$set : {v : 1}})`" --quiet"
Run Code Online (Sandbox Code Playgroud)
mydata集合中只有一个文档,我想将其v
字段设置为1
.但是,上面的表达式SyntaxError: invalid property id (shell eval):1
从Powershell脚本运行时返回,并且不更新文档.
更令人困惑的是,以下工作符合预期:
Invoke-Expression "& `"C:\MongoDB\bin\mongo.exe`" localhost:27017/mydb --eval `"printjson(db.mydata.findOne())`" --quiet"
Run Code Online (Sandbox Code Playgroud)
我有什么想法可能做错了吗?
更新:
解决方案:
Invoke-Expression '& "C:\MongoDB\bin\mongo.exe" localhost:27017/mydb --eval "db.mydata.update({}, {`$set : {v : 2}})" --quiet'
Run Code Online (Sandbox Code Playgroud) 在阅读有关使用owin和webapi的autofac的问题和文章后,我遇到了注入服务的解决方案,但它不起作用.这是我的代码:
public class StartUp
{
public void Configuration(IAppBuilder app)
{
HttpConfiguration config = new HttpConfiguration();
WebApiConfig.Register(config);
var builder = new ContainerBuilder(); // Create the container builder.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); // Register the Web API controllers.
var authcontext = new AuthContext();
builder.RegisterInstance(authcontext).AsSelf().SingleInstance();
//Updated
//var simpleauth = new SimpleAuthorizationServerProvider();
//Updated
// builder.RegisterInstance(simpleauth).SingleInstance().AsSelf().PropertiesAutowired();
builder.Register(x => new UserStore<IdentityUser>(authcontext)).As<IUserStore<IdentityUser>>();
//updated
builder.Register(x =>
{
var p = new SimpleAuthorizationServerProvider();
var userStore = x.Resolve<IUserStore<IdentityUser>>();
p.userManager = new UserManager<IdentityUser>(userStore);
return p;
}).AsSelf().PropertiesAutowired();
builder.RegisterType<AuthRepository>().As<IAuthRepository>().InstancePerRequest().PropertiesAutowired();
var container = builder.Build();
var resolver = …
Run Code Online (Sandbox Code Playgroud)