小编Ali*_*hşi的帖子

DbContext处理?

的DbContext

public class HaberPortalDB : DbContext
{
    public DbSet<Haberler> Haberler { get; set; }
    public DbSet<Kategoriler> Kategoriler { get; set; }
    public DbSet<Yazarlar> Yazarlar { get; set; }
}

public class Haberler
{
    public virtual int Id { get; set; }
    public virtual string Baslik { get; set; }
    public virtual string Aciklama { get; set; }
    public virtual string Icerik { get; set; }

    public virtual int YazarId { get; set; }
    public virtual Yazarlar Yazar { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc entity-framework idisposable

6
推荐指数
1
解决办法
7308
查看次数

数据注释本地化

模型

[MetadataType(typeof(UserMetaData))]
public class User
{
    public int Id { get; set; }
    public string UserName { get; set; }
}

public class UserMetaData
{
    public int Id { get; set; }

    [Required(ErrorMessageResourceType = typeof(Resources.ModelValidation), ErrorMessageResourceName = "UserNameRequired")]
    [LocalizedDisplayNameAttribute("UserName", NameResourceType = typeof(Resources.ModelValidation))]
    public string UserName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

视图

@using (Html.BeginForm())
{
    <div>
        @Html.LabelFor(x => x.UserName)
        @Html.TextBoxFor(x => x.UserName)
        @Html.ValidationMessageFor(x => x.UserName)
    </div>
    <div>
        <input type="submit" value="Gönder" />
    </div>
}
Run Code Online (Sandbox Code Playgroud)

LocalizedDisplayNameAttribute

public class LocalizedDisplayNameAttribute : DisplayNameAttribute
{
    private …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc localization data-annotations asp.net-mvc-4

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

Visual Studio 2017 不记得选项“在解决方案资源管理器中跟踪活动项目”

VS 不记得这个选项是勾选的,当重新启动 IDE 或更改项目分支时。

当我打开 IDE 时,我总是选中这个选项。

我正在使用 VS 17 Enterprise 最新版本。

编辑:我也在使用 resharper(也许它会覆盖 VS 选项)。

visual-studio visual-studio-2017

6
推荐指数
1
解决办法
512
查看次数

ASP.NET默认的MVC4应用程序内容页面没有布局参考?

我创建了一个mvc4网络应用程序.用剃刀视图引擎.您知道布局页面和内容页面(主页,联系人,关于等).但是没有引用内容页面的布局.

内容页面不应包括:

Layout = "~/Views/Shared/_Layout.cshtml";
Run Code Online (Sandbox Code Playgroud)

在内容页面中,这段代码丢失了.它们有效.没有布局参考,它如何做到这一点?

partial-views razor asp.net-mvc-4

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

DateTime比较没有时间部分?

我写了这段代码.但我想忽略时间,我只想比较一天.

from s in sayac_okumalari
where s.okuma_tarihi == startDate && s.sayac_id == sayac_id
group s by new { date = new DateTime(((DateTime)s.okuma_tarihi).Year, ((DateTime)s.okuma_tarihi).Month, ((DateTime)s.okuma_tarihi).Day, ((DateTime)s.okuma_tarihi).Hour, 1, 1) } into g
select new
{
     okuma_tarihi = g.Key.date,
     T1 = g.Sum(x => x.toplam_kullanim_T1),
     T2 = g.Sum(x => x.toplam_kullanim_T2),
     T3 = g.Sum(x => x.toplam_kullanim_T3)
};
Run Code Online (Sandbox Code Playgroud)

例如:

25.02.1987 == 25.02.1987
Run Code Online (Sandbox Code Playgroud)

.net c# linq datetime date-comparison

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

带有坐标的Google地图?

我想使用谷歌geochart与坐标(longtitute,latitute).但是我找不到关于这个主题的任何例子.区域和城市的例子有很多例子.但是我找不到坐标.

请,代码示例,链接,教程别的什么?

谢谢.

google-visualization

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

特定时间间隔内的重复性任务?

例如,我想以特定的时间间隔(每小时或每日任务)调用一个函数.

我已经在使用Timer了.但只要我的本地服务器正常工作,它就能工作.例如:

public static void StartYahooWeatherManager()
{
    Timer t = new Timer(1000 * 60 * 60 * 6  /* 6 hours */);
    t.Elapsed += new ElapsedEventHandler(WriteYahoWeatherRssItemToDb);
    t.Start();
}

private static void WriteYahoWeatherRssItemToDb(object o, ElapsedEventArgs e)
{
    YahooWeatherManager.InsertYahooWeatherRssItem(YahooWeatherManager.GetYahooWeatherRssItem());
}
Run Code Online (Sandbox Code Playgroud)

我以6小时为间隔向db发送天气信息.项目已经在主持人.只要我的计算机本地服务器正在运行,Timer事件就会起作用.

题:

我的代码有什么问题?(或者在WebProject中使用计时器的逻辑错误?)为什么计时器只在本地服务器工作时工作?

管理时间间隔任务的最佳方法是什么?(不需要asp.net)

我希望,我可以解释这个问题.谢谢.

.net c# asp.net-mvc timer scheduled-tasks

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

如何使用java脚本在文件上载中获取没有扩展名的文件名

我将使用asp.net中的文件上传控件上传文件.现在我想使用java脚本获取没有扩展名的文件名.我想验证文件名应该只是整数格式

$(function () {
    $('#<%=File1.ClientID %>').change(function () {
         var uploadcontrol = document.getElementById('<%=File1.ClientID%>').value;
    })
})
Run Code Online (Sandbox Code Playgroud)

javascript asp.net file-upload

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

Asp.net核心2.1单元测试自动播放器?

错误信息

消息:System.InvalidOperationException:Mapper未初始化.使用适当的配置调用Initialize.如果您正试图通过容器或以其它方式使用映射器实例,请确保您不必静态Mapper.Map方法的任何电话,如果你使用ProjectTo或UseAsDataSource扩展方法,确保你在适当的IConfigurationProvider通实例.

应用项目

定义映射配置文件(ApplicationMappingProfile.cs)

public class ApplicationMappingProfile : Profile
{
    public ApplicationMappingProfile()
    {
        CreateMap<User, UserListDto>();
        CreateMap<Permission, PermissionListDto>();
        // add auto mapper mapping configurations here
    }
}
Run Code Online (Sandbox Code Playgroud)

注册automapper服务(ApplicationServiceCollectionExtensions.cs)

public static class ApplicationServiceCollectionExtensions
{
    public static IServiceCollection AddKodkodApplication(this IServiceCollection services)
    {
        services.AddAutoMapper();

        //todo: add conventional registrar
        services.AddTransient<IUserAppService, UserAppService>();
        services.AddTransient<IPermissionAppService, PermissionAppService>();

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

单元测试项目

创建一个测试服务器以运行Startup.cs(ApiTestBase.cs)

public class ApiTestBase : TestBase
{
    protected static HttpClient Client;

    public ApiTestBase()
    {
        //if this is true, Automapper is throwing …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing automapper asp.net-core

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

如何在Asp.Net MVC中导出到excel?

脚本

function PostExportValues(meter_id, range_type_id, start_date, end_date, returnUrl) {
    var meter = $("#meter_selection").val()[0];
    $.ajax({
        url: '@Url.Action("GridExportToExcel", "Widget")',
        type: 'POST',
        data: { MeterType: meter_id, DateRangeType: range_type_id, StartDate: start_date, EndDate: end_date, returnUrl: returnUrl, Meter: meter },
        success: function () {
            alert("Success.");
        },
        error: function () {
            alert("Error!");
        }
    });   //end ajax
} //end PostExportValues
Run Code Online (Sandbox Code Playgroud)

CONTROLLER

public void GridExportToExcel(int MeterType, int DateRangeType, DateTime? StartDate, DateTime? EndDate, string returnUrl, int Meter)
{
    Customers customer = CustomerManager.GetCustomer(WebSecurity.CurrentUserId);
    //if start date is null, then set it to …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc export-to-excel

4
推荐指数
1
解决办法
8012
查看次数