我有一个包含登录表单的部分视图.我想将它从ajax调用渲染到我的控制器.
这是我将返回部分视图的示例:
postlogin: function (req,res) {
var username = req.param('username');
var password = req.param('password');
User.find({
username: username,
password: password.salt()
}).done(function(err, users){
if(users.length == 1){
// Here I want to return a partial view, not a view
res.view('home/login', {message: 'Login success!'});
}else{
// Here I want to return a partial view, not a view
res.view('home/login', {message: 'Login failed!'});
}
});
},
Run Code Online (Sandbox Code Playgroud) 有没有办法在Sails.js中进行模型之间的关系映射?
这就是我想要的:
的Video.js:
module.exports = {
attributes: {
filename: 'STRING',
length: 'INTEGER',
watchCount: 'INTEGER',
extension: 'STRING'
user: // I wan to reference to my User.js model
}
};
Run Code Online (Sandbox Code Playgroud)
在我的User.js中:
module.exports = {
attributes: {
username: {
type: 'email',
required: true
},
password: 'STRING',
videos: // I would like to have an array of videos after querying a user
}
};
Run Code Online (Sandbox Code Playgroud) 是否可以在注册表中注册接口,然后"重新注册"它以覆盖第一次注册?
IE:
For<ISomeInterface>().Use<SomeClass>();
For<ISomeInterface>().Use<SomeClassExtension>();
Run Code Online (Sandbox Code Playgroud)
我在运行时想要的是我的对象工厂SomeClassExtension在我要求时返回ISomeInterface.
提前致谢!
我正在尝试IValidatableObject在 web api 2 上下文中使用验证。该Validate方法正在被调用,但ValidationContext传递的参数有一个调用的方法GetService,该方法始终返回 null,因为从未设置验证上下文的服务提供者。
从我所有的研究来看,我们可以轻松地在 MVC 框架中配置它,但我没有找到任何关于如何在 web api 2 中配置它的信息。
在验证传递给 的模型时,我们如何将服务提供者设置为验证上下文ApiController?
c# validation ivalidatableobject asp.net-apicontroller asp.net-web-api2
我有一种情况,我需要一个这种类型的密钥字典,但它似乎没有找到等效的密钥.
Dictionary<Tuple<int[], int>, object> cache = new Dictionary<Tuple<int[], int>, object>();
cache.Add(Tuple.Create(new int[]{1}, 1), new object());
Assert.That(cache.ContainsKey(Tuple.Create(new int[] { 1 }, 1))); // This fails
Run Code Online (Sandbox Code Playgroud)
我已经通过使用a来测试它Tuple<int, int>,它似乎工作得很好,但在我的情况下,我真的需要某种Tuple<int[], int>类型的键,它不起作用.
还有其他替代方案吗?
c# ×3
javascript ×2
node.js ×2
sails.js ×2
dependencies ×1
dictionary ×1
mapping ×1
one-to-many ×1
registry ×1
structuremap ×1
validation ×1