我有以下viewmodel定义
public class AccessRequestViewModel
{
public Request Request { get; private set; }
public SelectList Buildings { get; private set; }
public List<Person> Persons { get; private set; }
}
Run Code Online (Sandbox Code Playgroud)
所以在我的应用程序中,访问请求必须至少有一个人.您可以使用什么方法进行验证?我不希望在我的控制器中进行这种验证,这很简单.是自定义验证属性的唯一选择吗?
编辑:目前正在使用FluentValidation执行此验证(漂亮的库!)
RuleFor(vm => vm.Persons)
.Must((vm, person) => person.Count > 0)
.WithMessage("At least one person is required");
Run Code Online (Sandbox Code Playgroud) 是否可以从typescript模块导出一个简单的函数?
module SayHi {
export function() {
console.log("Hi");
}
}
new SayHi();
Run Code Online (Sandbox Code Playgroud)
这种情况发生在我的比较视图和标准提交中,文件数量变化很大.
下面的截图来自两个分支之间的比较,其中380个文件已更改.差异日志开头的文件可以看到它们的差异,但是在页面的某个点上它停止可视化差异.我知道你不想要大量的页面,但我似乎找不到单独查看文件差异的方法.相反,我必须在本地检查这些并手动完成差异.
有没有人有一个更简单的解决方案,无论是软件驱动还是(最好)一个我在github上缺少的链接?

我有一个依赖的模块Backbone.我有一个backbone.d.ts定义,但TypeScript似乎不想编译我的模块,除非我的
import Backbone = module("backbone")
Run Code Online (Sandbox Code Playgroud)
实际上指向有效的主干模块而不是定义文件.我正在使用AMD加载的模块,并为骨干网定义了一个requirejs垫片.
除了创建一个虚假的backbone.ts模块定义之外,还有解决方法吗?
更新:解决方案的副作用是此类代码不再有效,因为模块不再存在.它需要存在因为requirejs垫片.我所知道的唯一解决方法是拥有两个.d.ts文件.一个用于使用骨干作为导入但不包含该declare module位的文件.另一个使用/// <reference它确实包括declare module线.
/// <reference path="../dep/backbone/backbone.d.ts" />
interface IApi {
version: number;
Events: Backbone.Events;
}
Run Code Online (Sandbox Code Playgroud) 我想用行动链接包装一个跨度,因为我坚持现有的CSS主题.它看起来并不像任何Html.ActionLink构造者所允许的那样.可能的解决方案:
如果#2是唯一的方式我有两个问题.
我在ubuntu上.从ubuntu存储库安装节点,一切都很好.我试图安装的其中一个模块需要node-waf所以我从源安装了最新的不稳定节点.现在npm坏了.想要回到节点0.4稳定但是当我从源版本卸载时我遇到了问题.
sudo make uninstall,成功)bash: /usr/local/bin/node: No such file or directory如何让它停止在该路径中寻找节点?Ubuntu repo节点二进制文件仍然存在/usr/bin/node.运行
cd /usr/bin ; ./node -v
Run Code Online (Sandbox Code Playgroud)
工作和吐出v0.4.12.
运行
cd /usr/bin ; node
Run Code Online (Sandbox Code Playgroud)
错误.
我已经阅读了嵌套映射维基页面,但似乎不喜欢多层嵌套.我已经创建了以下地图并定义了类.
AutoMapper.Mapper.CreateMap<Address, AddressDTO>();
AutoMapper.Mapper.CreateMap<MatchCompanyRequest, MatchCompanyRequestDTO>();
public class MatchCompanyRequest
{
Address Address {get;set;}
}
public class MatchCompanyRequestDTO
{
public CompanyInformationDTO {get;set;}
}
public class CompanyInformationDTO {get;set;}
{
public string CompanyName {get;set;}
public AddressDTO Address {get;set;}
}
Run Code Online (Sandbox Code Playgroud)
但是以下代码......
// works
matchCompanyRequestDTO.companyInformationDTO.Address =
AutoMapper.Mapper.Map<Address, AddressDTO>(matchCompanyRequest.Address);
// fails
matchCompanyRequestDTO =
AutoMapper.Mapper
.Map<MatchCompanyRequest, MatchCompanyRequestDTO>(matchCompanyRequest);
Run Code Online (Sandbox Code Playgroud)
这种深度嵌套是否有效,而且我的配置不正确?或者这种嵌套还没有得到支持?
- 编辑
对于任何有兴趣的人,我都无法控制DTO.
更新:感谢此处的帮助,我创建了以下解决方案:
public class CustomAuthorize : AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
// Returns HTTP 401 - see comment in HttpUnauthorizedResult.cs
// If user is not logged in prompt
if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
{
base.HandleUnauthorizedRequest(filterContext);
}
// Otherwise deny access
else
{
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary {
{"controller", "Account"},
{"action", "NotAuthorized"}
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
我从NerdDinner开始,使用FormsAuthentication和ActiveDirectory作为我的会员提供者.我通过我的数据库使用Global.asax和AccountController(下面)添加了对角色的支持.
所以现在在我的控制器中,我的Authorize属性设置为仅限admin的角色(下面).我登录的用户是作者.当我点击删除时,它会要求我登录,即使我已经这样做了.我在哪里可以使用逻辑返回拒绝访问视图?
的Global.asax.cs
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
HttpCookie authCookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];
if (authCookie == null || authCookie.Value == "")
{ …Run Code Online (Sandbox Code Playgroud) This code snippet worked in 1.7.2 with both success/error callbacks as well as promises style callbacks. With 1.8.2 the success/error callbacks still work but the promises do not. My hunch is that the return dfd.promise(jqXHR); line is the problem but im not certain.
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
// Don't infinitely recurse
originalOptions._retry = isNaN(originalOptions._retry)
? Common.auth.maxExpiredAuthorizationRetries
: originalOptions._retry - 1;
// set up to date authorization header with every request
jqXHR.setRequestHeader("Authorization", Common.auth.getAuthorizationHeader());
// save the original error callback for …Run Code Online (Sandbox Code Playgroud) 我有一个div的集合作为行,可以是可变宽度,因为它们在可调整大小的容器内.div包含我想要悬挂缩进的文本.这工作正常,但在此示例中,当宽度太低时,第一行被推到红色标签下面.
什么时候.wrapper450px一切正常显示.当它是250px时,你可以看到事情是如何破裂的.我总是希望longtextthatwraps跨度与红色标签位于同一行.
这是一个实例/小提琴,来源如下:
HMTL (两者之间没有空格.prefix,.part但为了便于阅读......):
<div class="wrapper">
<div class="padded excludes">
<div class="parts first">
<span class="prefix">Quisques: </span>
<span class="segment level-0">
<span class="part text">longtextthatwraps incorrectly (<a href="#" class="code">0000</a>-<a href="#" class="code">0000</a>)</span>
</span>
</div>
<div class="parts">
<span class="segment level-0">
<span class="part text">consectetur adipiscing (<a href="#" class="code">0000</a>-<a href="#" class="code">0000</a>)</span>
</span>
</div>
<div class="parts">
<span class="segment level-0">
<span class="part text">quisque non mauris sed:</span>
</span>
</div>
<div class="parts">
<span class="segment level-1">
<span class="part list-item">hendrerit (<a href="#" class="code">0000</a>-<a href="#" …Run Code Online (Sandbox Code Playgroud)