小编Ser*_*rov的帖子

MVC 6标签助手和foreach

为了显示集合中的项目,我将为asp-for标签标签助手的属性提供什么?下面的代码生成编译错误.

@foreach (var item in Model)
{
    <label asp-for="item.BookingCode"></label>
}
Run Code Online (Sandbox Code Playgroud)

collections asp.net-core-mvc tag-helpers

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

MVC6替代@ Html.DisplayFor

MVC6引入了Tag Helpers,与使用@ Html.EditorFor等相比,这是更好的方法.但是我还没有发现任何Tag Helper可以替代@ Html.DisplayFor.

当然,我可以直接在Razor页面上使用变量,例如@ Model.BookingCode.但这不允许控制格式.

使用MVC6,显示模型属性值的概念正确方法是什么?

razor asp.net-core-mvc

20
推荐指数
2
解决办法
8226
查看次数

在Entity Framework Core中使用[ComplexType]

我在EF Core数据模型中使用了我自己的类的属性.

public class Currency
{
    public string Code { get; set; }
    public string Symbol { get; set; }
    public string Format { get; set; }
}

[ComplexType]
public class Money
{
    public int? CurrencyID { get; set; }
    public virtual Currency Currency { get; set; }
    public double? Amount { get; set; }
}

public class Rate
{
    public int ID { get; set; }
    public Money Price = new Money();
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,当我尝试创建迁移时,EF Core报告错误.

Microsoft.Data.Entity.Metadata.ModelItemNotFoundException: The entity type …
Run Code Online (Sandbox Code Playgroud)

entity-framework-core asp.net-core-mvc

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

MVC 6标记助手作为编辑器模板的替代品

MVC 6引入了Tag Helpers作为@ Html.EditorFor的更好替代品.可以创建自定义编辑器模板.也可以创建自定义Tag Helper.

但是,在创建Tag Helper时,需要通过C#代码(使用TagBuilder等)创建HTML.对于复杂的Tag Helpers,它不如使用Razor语法那么方便.

有没有什么方法可以让我从Razor页面创建自定义Tag Helper?

asp.net-core-mvc tag-helpers

13
推荐指数
1
解决办法
6041
查看次数

在IIS上运行MVC 6 Beta 8应用程序

我正在尝试发布我的MVC 6 Beta 8应用程序.我能够成功地将它发布到Azure,但是当我尝试将其发布到ASPHostPortal时,我收到500错误.

所以我尝试将应用程序发布到本地IIS,但也失败了.首先,我发现我需要安装HttpPlatformHandler(否则IIS无法加载web.config).但即使在那之后,我也得到了502.3错误.

HTTP Error 502.3 - Bad Gateway
There was a connection error while trying to route the request.
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

同样在事件日志中,我可以从HttpPlatformHandler看到错误1000而没有描述.但它说"进程'0'未能启动.端口= 13679,错误代码='-2147024894'."

stdout.log已创建但为空.

这是我的web.config:

<configuration>
  <system.webServer>
    <handlers>
      <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="true" stdoutLogFile="stdout.log" startupTimeLimit="3600"></httpPlatform>

    <httpErrors errorMode="Detailed" />
    <asp scriptErrorSentToBrowser="true" />
  </system.webServer>

  <system.web>
    <customErrors mode="Off" />
    <compilation debug="true" />
  </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

我从哪里开始?

asp.net-mvc iis-8 asp.net-core-mvc

9
推荐指数
1
解决办法
3379
查看次数

有没有办法从Visual Studio Code调试Tomcat Java应用程序

我是Java的新手,但需要对Java代码进行一些更改.我更喜欢使用Visual Studio Code.Java代码使用Maven构建到.WAR文件,并部署到Tomcat.

有没有办法直接从Visual Studio Code调试此应用程序?

java debugging tomcat visual-studio-code

9
推荐指数
1
解决办法
2434
查看次数

在MVC 6中调整上传的图像大小

在MVC 6中调整上传图像大小的最佳方法是什么?我想存储图像的多个变体(例如小,大等),以便能够选择稍后显示的内容.

这是我的行动代码.

    [HttpPost]
    public async Task<IActionResult> UploadPhoto()
    {
        if (Request.Form.Files.Count != 1)
            return new HttpStatusCodeResult((int)HttpStatusCode.BadRequest);

        IFormFile file = Request.Form.Files[0];

        // calculate hash
        var sha = System.Security.Cryptography.SHA256.Create();
        byte[] hash = sha.ComputeHash(file.OpenReadStream());

        // calculate name and patch where to store the file
        string extention = ExtentionFromContentType(file.ContentType);
        if (String.IsNullOrEmpty(extention))
            return HttpBadRequest("File type not supported");

        string name = WebEncoders.Base64UrlEncode(hash) + extention;
        string path = "uploads/photo/" + name;

        // save the file
        await file.SaveAsAsync(this.HostingEnvironment.MapPath(path));
     }
Run Code Online (Sandbox Code Playgroud)

image asp.net-core-mvc

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

为什么List <>实现RemoveAll,但IList <>不实现

我正在重构我的代码以使用IList而不是List.我在几个地方使用了List.RemoveAll,并注意到IList根本没有这个方法.这有什么好的理由吗?

c# list

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

在IIS Express上运行MVC6 Beta8应用程序

我刚刚更新到MVC6 Beta8.几个小时后修复代码再次编译,我遇到了一个问题,即应用程序无法在IIS Express下运行.我收到此错误消息:

[TypeLoadException:无法从程序集'Microsoft.Dnx.Host.Clr,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = adb9793829ddae60'加载类型'Microsoft.Dnx.Host.Clr.EntryPoint'.] System.Web.HttpRuntime .HostingInit(HostingEnvironmentFlags hostingFlags,PolicyLevel policyLevel,Exception appDomainCreationException)+303

[HttpException(0x80004005):无法从程序集"Microsoft.Dnx.Host.Clr,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = adb9793829ddae60'.]系统加载"Microsoft.Dnx.Host.Clr.EntryPoint"类型. Web.HttpRuntime.FirstRequestInit(HttpContext context)+9922864 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)+90 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext context)+261

我知道主机架构有变化.但这是否意味着我们不能再使用IIS express了,或者仅仅是更新或配置更改的问题?

iis-express asp.net-core-mvc asp.net-core

6
推荐指数
2
解决办法
3280
查看次数

EF7和GroupBy()无法翻译

我在EF7 Beta 8上运行以下代码:

var locationGrops = from l in db.Locations
                    group l by l.ServiceType into g
                    select g;

var list = locationGrops.ToList();
Run Code Online (Sandbox Code Playgroud)

当我执行此代码时,EF会显示警告.

warning : [Microsoft.Data.Entity.Query.QueryCompilationContext] The LINQ express
ion 'GroupBy([l].ServiceType, [l])' could not be translated and will be evaluate
d locally.
Run Code Online (Sandbox Code Playgroud)

查询对我来说似乎很基础,SQL中有GROUP BY.有没有办法让它在服务器上运行?

entity-framework-core asp.net-core-mvc

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

为什么 QueryTrackingBehavior 不应该默认为 NoTracking?

在寻找 Entity Framework 7 RC1 问题的解决方法(将实体状态设置为 Add after ToList() 以进行复杂查询)时,我找到了 db.ChangeTracker.QueryTrackingBehavior 属性并将其设置为 NoTracking。这解决了问题。

我更喜欢这种方法,因为它允许我手动控制写入数据库的内容 - 我只需要将所有已更改或添加的实体标记为已更改/已添加。

这种方法是否有缺点,而不是需要手动将修改后的实体的状态设置为已修改?

entity-framework-core asp.net-core-mvc

5
推荐指数
0
解决办法
414
查看次数

增加Azure WebApp for Containers的启动超时

我们在Azure WebApp for Containers上的Docker中运行Java Spring Boot应用程序.单个B1实例足以让应用程序运行,但Spring Boot在启动时非常慢,并且可能需要240秒才能启动应用程序.

结果Azure WebApp for Containers在240秒后杀死容器,没有给它足够的时间来启动.

有没有办法更改默认的240秒启动超时?

docker spring-boot azure-web-app-service azure-web-app-for-containers

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