小编Chr*_*ian的帖子

实现接口包括抛出新的NotImplementedException ...为什么?

我正在使用VS2017社区,它昨天刚收到更新.今天我想实现一个接口,现在实现如下:

public string City 
{ 
    get => throw new NotImplementedException(); 
    set => throw new NotImplementedException(); 
}
Run Code Online (Sandbox Code Playgroud)

而不是这(我的预期):

public string City { get; set; }
Run Code Online (Sandbox Code Playgroud)

为何如此改变?不确定这是否特定于C#7或VS或其他什么.我只知道接口的自动实现在过去一周左右发生了变化.

我的界面:

public interface IMyInterface
{
    string City { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

c# visual-studio-2017

27
推荐指数
3
解决办法
4503
查看次数

无法使用ASP.NET Core Web API与IIS协同工作

我正在构建一个ASP.NET核心MVC Web Api应用程序,我正试图让它在我自己的机器上使用IIS.我已经阅读了不同的博客并尝试了不同的东西,但似乎无法让它工作......我的Winform客户端在调用Web API时只获得404.通过网络浏览器导航到网站roo给我一个HTTP错误403.14 - 禁止.

我正在运行Windows 10 Pro.IIS已安装.已安装ASP.NET Core Server Hosting Bundle

我在IIS中添加了该网站.应用程序池设置为"无管理代码".在VS2015中,我将网站发布到本地文件夹.我将该文件夹的内容复制到IIS正在查找的网站文件夹中.然后我会期望它工作,但它没有:(

这是我的设置:

web.config中

  <system.webServer>
<handlers>
  <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<directoryBrowse enabled="true"/>
<aspNetCore processPath="%LAUNCHER_PATH%"
      arguments="%LAUNCHER_ARGS%"
      stdoutLogEnabled="true"
      stdoutLogFile=".\logs\aspnetcore-stdout"
      forwardWindowsAuthToken="false" />
Run Code Online (Sandbox Code Playgroud)

Program.cs中

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseWebRoot("wwwroot")
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();

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

StartUp.cs

        public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
            .AddEnvironmentVariables();
        Configuration = builder.Build(); …
Run Code Online (Sandbox Code Playgroud)

c# iis asp.net-web-api .net-core asp.net-core-webapi

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

更改日期格式验证,mvc 3和jQuery

我已经解决了这个问题两天了,仍然没有找到解决方案...我已经使用本教程在我的网站上添加了一个datepicker:http: //blogs.msdn.com/b/stuartleeks/archive/2011/ 1月25日/ ASP净MVC -3-积分-与最jquery的-UI-日期选择器-和-添加-A-jQuery的验证最新范围-validator.aspx

一切都有效,除了验证.我一直收到错误"请输入有效日期".我已将我的解决方案中的所有内容更改为"dd-MM-yyyy"并添加了全球化文化="da-DK"uiCulture ="da-DK"

到我的web.config.我还在努力工作.继续得到错误.我可以改变我的模特课吗?我要验证的日期:

    [DataType(DataType.Date)]
    public DateTime DateOfBooking { get; set; }
Run Code Online (Sandbox Code Playgroud)

试过:

    $('#formatdate').change(function () {
        $('#datpicker').datepicker("option", "dateFormat", "dd-mm-yy");
    });
Run Code Online (Sandbox Code Playgroud)

和:

$(document).ready(function () {
function getDateYymmdd(value) {
    if (value == null)
        return null;
    return $.datepicker.parseDate("dd-mm-yy", value);
}
$('.date').each(function () {
    var minDate = getDateYymmdd($(this).data("val-rangedate-min"));
    var maxDate = getDateYymmdd($(this).data("val-rangedate-max"));
    $(this).datepicker({
        dateFormat: "dd-mm-yyyy",  // hard-coding uk date format, but could embed this     as an attribute server-side (based on the current culture)
        minDate: minDate,
        maxDate: maxDate
    }); …
Run Code Online (Sandbox Code Playgroud)

validation jquery date asp.net-mvc-3

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

Asp.net core 3.1 找不到要渲染的 Razor 组件

我正在尝试将 Blazor 集成到现有的 asp.net core 3.1 应用程序中。我看过的所有教程都说,在 web 项目中进行正确设置后,您应该能够在任何 cshtml 文件中执行此操作:

<component>
    @(await Html.RenderComponentAsync<HelloComponent>(RenderMode.ServerPrerendered))
</component>
Run Code Online (Sandbox Code Playgroud)

但是我得到了这个: 在此处输入图片说明

找不到类型或命名空间“HelloComponent”。

我做了什么

1) 在我的 Startup.cs 中添加了以下内容

public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages();
    services.AddServerSideBlazor();
    // .. removed other services...
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseRouting();            
    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
        endpoints.MapControllers();
        endpoints.MapRazorPages();
        endpoints.MapBlazorHub();
    });
    // .. removed the rest of configuration..
}
Run Code Online (Sandbox Code Playgroud)

2) 将 _Imports.razor 文件添加到 /Pages 文件夹

@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop …
Run Code Online (Sandbox Code Playgroud)

.net asp.net-core blazor razor-components

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

使用javascript在MVC中调用控制器方法

我试图使一个表行作为我的mvc网站中另一个视图的链接.我不想使用自动生成的表列表提供的标准"详细信息"链接,而是使用表格行作为"详细信息"视图的链接.所以我需要以某种方式将行作为链接.每个rom都有一个唯一的id,我需要传递给控制器​​方法.我尝试了不同的解决方案但是当我按下表格行时发生了注意......

到目前为止,这就是我所拥有的:

<script type="text/javascript">
$(document).ready(function(){
    $('#customers tr').click(function () {
        var id = $(this).attr('id');
        $.ajax({
            url: "Customer/Details" + id,
            succes: function () { }
        });
    })
})
</script>
Run Code Online (Sandbox Code Playgroud)

我的控制器方法:

public ActionResult Details(int id)
{
    Customer model = new Customer();
    model = this.dbEntities.Customers.Where(c => c.Customer_ID == id).Single();
    return View(model);
}
Run Code Online (Sandbox Code Playgroud)

Global.asax中:

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new HandleErrorAttribute());
}

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", …
Run Code Online (Sandbox Code Playgroud)

javascript ajax asp.net-mvc jquery

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

如何使用包含相同元素/类的different.xsd命名空间?

我有点理解我应该如何处理xml文件,所以我希望你们可以指导我正确的dirrection :)希望我能够解释我的问题清楚:)

我有很多.xsd文件都是从上到下连接的.所以我有10个带有命名空间A的.xsd和带有命名空间B的10个.xsd.让我们说两个命名空间代表每个自己的汽车.这意味着它们共享许多相同的元素,如引擎,滚轮等.我认为我可以使用xsd.exe,然后只需在我的C#代码中序列化xml文件.但是,当我将.xsd文件转换为两个.cs文件(每个命名空间/汽车一个)时,它们共享许多相同的类.当我想将两个.cs文件添加到我的项目时,这会产生问题.不能有两个同名的班级......我该如何解决这个问题?我使用错误的工具还是完全误解了我应该做什么?:)

.cs文件的开头:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.261
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System.Xml.Serialization;

// 
// This source code was auto-generated by xsd, Version=4.0.30319.1.
// 


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]          [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2006/07/01/")]
[System.Xml.Serialization.XmlRootAttribute("FixedFont",     Namespace="http://rep.oio.dk/sundcom.dk/medcom.dk/xml/schemas/2006/07/01/", IsNullable=false)]
public partial class SimpleFormattedText {

private object[] itemsField;

private ItemsChoiceType[] itemsElementNameField;

private string[] textField;

/// …
Run Code Online (Sandbox Code Playgroud)

c# xml xsd xsd.exe

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

添加服务引用时,在app.config中未生成端点

我需要消耗一些wcf,但我已经坚持添加服务参考:)我做什么:

  1. 创建新的Windows窗体项目.
  2. 右键单击该项目,然后按"添加服务引用".
  3. 插入svc地址并按"Go".

在此输入图像描述

在此输入图像描述

然后添加服务,但是当我查看我的app.config时它只包含这个

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我的端点在哪里?他们应该在添加服务引用时生成它们吗?

c# wcf

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

有没有正确的方法来使用db上下文类?

我想知道在使用Web站点的上下文类连接到db时,性能和一般最佳实践的差异是什么.考虑这两种不同的方法时,最好的方法是什么:

public class Repository()
{
    Private Context context;

    public List<User> GetUsers()
    {
        return this.context.Users.ToList();
    }
Run Code Online (Sandbox Code Playgroud)

要么

public class Repository()
{        
    public List<User> GetUsers()
    {
        using (Context context = new context())
        {
            return context.Users.ToList(); 
        }
    }
 }
Run Code Online (Sandbox Code Playgroud)

如果它将结果作为a List或as 返回是否重要IEnumerable

c# entity-framework dbcontext

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