小编Moh*_*ari的帖子

AutoMapper Enum to byte with implementation IMapperConfigurator

枚举定义是

public enum RowStatusEnum
{
    Modified = 1,
    Removed = 2,
    Added = 3
}

public class RowStatusEnumConvertor : IMapperConfigurator
{
    public void Cofigure()
    {
        Mapper.CreateMap<RowStatusEnum, byte>();
        Mapper.CreateMap<byte, RowStatusEnum >();
    }
}
Run Code Online (Sandbox Code Playgroud)

我在RowStatusEnumConvertor类中使用Implemention IMapperConfigurator配置autoMapper,但是没有使用此代码而不映射此类型,我认为我的配置不正确或不够,请帮帮我

谢谢

automapper c#-4.0

10
推荐指数
3
解决办法
1万
查看次数

asp.net核心标记帮助器,用于有条件地将类添加到元素

在Asp.Net MVC中,我们可以有条件地添加类,如下代码:

<div class="choice @(Model.Active?"active":"")">
</div>
Run Code Online (Sandbox Code Playgroud)

如何通过使用tagHelper和删除条件中的其他部分来做到这一点.

tag-helpers asp.net-core

7
推荐指数
1
解决办法
5080
查看次数

如何在Asp.net核心中的ViewComponent之间共享ViewData

我有两个ViewComponent,我希望使用ViewData或其他技术来共享一些数据,然后在主视图中使用这些数据,但这不是方法,并且当ViewComponent的富到if条件时,每个ViewComponent的ViewData为null.

public class OneViewComponent : ViewComponent
{
    public async Task<IViewComponentResult> InvokeAsync(Page page, Zone zone)
    {
        //some operation

        string text = "one";

        if(ViewData["data"] != null)
        {
            ViewData["data"] = ViewData["data"].ToString() + text;
        }
        else
        {
            ViewData["data"] = text;
        }

        return View();
    }
}

public class TwoViewComponent : ViewComponent
{
    public async Task<IViewComponentResult> InvokeAsync(Page page, Zone zone)
    {
        //some operation

        string text = "two";

        if(ViewData["data"] != null)
        {
            ViewData["data"] = ViewData["data"].ToString() + text;
        }
        else
        {
            ViewData["data"] = text;
        }

        return View();
    } …
Run Code Online (Sandbox Code Playgroud)

c# viewdata asp.net-core asp.net-core-viewcomponent

7
推荐指数
2
解决办法
5464
查看次数

在基于asp.net声明的身份验证中更新声明

我有一个asp.net应用程序,我使用基于声明的身份验证进行身份验证.默认情况下,asp将用户的声明存储在cookie中(我认为).

我有一个管理面板,管理员可以更改用户的声明.例如,用户A具有"CRUD"声明(对于ClaimType ="Document"),admin决定将"CRUD"改为"CRU"(D被省略).

用户有"CRUD"声明,直到他的cookie过期,因为他在管理员决定之前登录.

我们如何强制更新用户的cookie以获得"CRU"声明.

asp.net authentication cookies asp.net-mvc claims-based-identity

6
推荐指数
0
解决办法
5530
查看次数

重定向以从另一个操作发布操作

我想从MVC3控制器中的另一个操作重定向到后期操作.我怎样才能做到这一点?

post action asp.net-mvc-3

5
推荐指数
1
解决办法
6332
查看次数

在angular指令中使用第三方lib

我想为persian datepicker创建一个angular指令,我想使用的javascript lib是http://jspersiandatepicker.codeplex.com/,我的代码是:

<input type="text" persiandatepicker ng-model="mydate" />{{mydate}}

directive('persiandatepicker', function() {
  return {
      restrict: 'A',
      require: '?ngModel',
      link: function (scope, element, attrs, ngModel) {
          if (!ngModel) return;

          ngModel.$render = function () {
              element.bind("click", function () {
              PersianDatePicker.Show(this, ngModel.$viewValue || '');
          });

      };
   }
};
});
Run Code Online (Sandbox Code Playgroud)

这个代码显示datepicker当点击输入时和选择日期显示在输入中,但模型没有绑定而不改变我怎么能在这个样本中进行绑定?plunker中的这个链接是我的代码:http://plnkr.co/edit/AQsvlbdGHCVpjMeCbR3c?p = preview

angularjs angularjs-directive

5
推荐指数
1
解决办法
1127
查看次数

离子在离子页脚杆中添加两个按钮

我想在离子页脚栏中添加两个按钮,如图片,但我的代码不能正常工作.

<ion-footer-bar class="bar-positive" padding="false">
    <h1 class="title col col-50 no-padding remove-filter">
        Button 333333333
    </h1>
    <h1 class="title col col-50 no-padding remove-filter">
        Button 333333333
    </h1>
</ion-footer-bar> 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

ionic-framework ionic

5
推荐指数
2
解决办法
1万
查看次数

实体框架中可重用的 linq 选择查询

在我的应用程序中,某些表需要多个报告,许多字段在大多数报告中都很常见,作为示例:

public class ReportStudent
{
    public int Id {get; set;}
    public string Name {get; set;}
    public string Family {get; set;}
    public DateTime BirthDate {get; set;}
    public DateTime RegisterDate {get; set;}
    public Double Average {get; set;}
    public string FatherName {get; set;}
    public string MotherName {get; set;}
}

var list1 = context.Students.Select(e=> new ReportStudent
{
    Id = e.Id
    Name = e.Name
    Family = e.Family
    BirthDate = e.BirthDate
    RegisterDate = e.RegisterDate
    FatherName = e.FatherName
    MotherName = e.MotherName
}).ToList();

var list2 = context.Students.Select(e=> new …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework

5
推荐指数
1
解决办法
1344
查看次数

在循环中调用具有相同输出和不同输入的多个方法

我有多种方法,具有不同的输入参数和相同的输出.

我使用输入类型的数字调用Method1,然后检查其结果,如果结果有效,则调用下一个方法(此时输入类型为字符串),依此类推.

在这个例子中我有三种方法,但如果我有10种方法或20种方法具有不同的输入和相同的输出我必须写冗余代码,我该如何防止这些冗余代码?

这是方法的示例:

public ValidationResult Method1(int number, string family)
{
    var validationResult = new validationResult();
    if(number > 10 || family="akbari")
    {
        validationResult.Errors.Add(new ValidationFailure("", "Invalid Number"));
    }
    return validationResult;
}

public ValidationResult Method1(string name)
{
    var validationResult = new validationResult();
    if(name.Length > 20)
    {
        validationResult.Errors.Add(new ValidationFailure("", "Invalid name"));
    }
    return validationResult;
}

public ValidationResult Method1(double average, string family)
{
    var validationResult = new validationResult();
    if(average < 14)
    {
        validationResult.Errors.Add(new ValidationFailure("", "Invalid average"));
    }
    return validationResult;
}
Run Code Online (Sandbox Code Playgroud)

我称这种方法如下:

var validationResult = …
Run Code Online (Sandbox Code Playgroud)

c# design-patterns

5
推荐指数
1
解决办法
793
查看次数

在Entity Framework核心中选择未加载导航属性后包含

我使用实体框架核心1.1.

我有一个如下所示的查询,我希望通过使用Include来加载UserProfile的用户加载UserProfile.但是此查询始终返回UserProfile null.

查询:

var user = dbContext.UserMappers
    .Where(e => e.OldUserId == id)
    .Select(e => e.User)
    .Include(e=>e.UserProfile)
    .FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)

楷模:

public class UserMapper
{
    [Key, ForeignKey(nameof(User))]
    public string UserId { get; set; }
    public User User { get; set; }
    public int OldUserId { get; set; }
}

public class User : IdentityUser
{
    public bool Suspended { get; set; }
    public string Nickname { get; set; }
    public virtual UserProfile UserProfile { get; set; }
}

public class UserProfile
{ …
Run Code Online (Sandbox Code Playgroud)

entity-framework entity-framework-core .net-core

5
推荐指数
1
解决办法
1728
查看次数