• mvc网站迁移.net core记录


    接口return Json()时序列号小写的问题

    在Startup.cs-》ConfigureServices方法配置一下解决

            public void ConfigureServices(IServiceCollection services)
            {
                // Add framework services.
                services.AddMvc()
                        .AddJsonOptions(op => op.SerializerSettings.ContractResolver =
                                              new Newtonsoft.Json.Serialization.DefaultContractResolver());
            }
    

    视图中输出中文会乱码

    图片
    ConfigureServices方法中配置即可,详情见院长文章 http://www.cnblogs.com/dudu/p/5879913.html

                services.Configure<WebEncoderOptions>(options =>
                {
                    options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All);
                });
    

    .net core中配置伪静态

    Configure方法中,还是一样的配方
    图片

             app.UseMvc(routes =>
                {
                    routes.MapRoute(
                        name: "index",
                        template: "index.html",
                        defaults: new { controller = "Home", action = "Index" }
                    );
                    routes.MapRoute(
                        name: "detail",
                        template: "detail/{id}.html",
                        defaults: new { controller = "Home", action = "Detail" }
                    );
                    routes.MapRoute(
                        name: "add",
                        template: "add.html",
                        defaults: new { controller = "Home", action = "Add" }
                    );
                    routes.MapRoute(
                        name: "default",
                        template: "{controller=Home}/{action=Index}/{id?}");
                });
    

    单个文件上传

            [HttpPost]
            public IActionResult Upload(IFormFile file)
            {
                string previewPath = "";//加域名什么的
                long size = 0;
                var upFileName = ContentDispositionHeaderValue
                       .Parse(file.ContentDisposition)
                       .FileName
                       .Trim('"');
                var fileName = Guid.NewGuid() + Path.GetExtension(upFileName);
                size += file.Length;
                if (size > UploadMaxLength)
                {
                    return Json(new
                    {
                        code = 0,
                        msg = "图片太大,不能超过5M"
                    });
                }
                previewPath += "/uploads/" + fileName;
                var savePath = _hostingEnv.WebRootPath + @"uploads" + fileName;
                var saveDir = _hostingEnv.WebRootPath + @"uploads";
    
                if (!Directory.Exists(saveDir))
                {
                    Directory.CreateDirectory(saveDir);
                }
                using (FileStream fs = System.IO.File.Create(savePath))
                {
                    file.CopyTo(fs);
                    fs.Flush();
                }
                return Json(new
                {
                    code = 0,
                    msg = "上传成功",
                    data = new
                    {
                        src = previewPath,
                        title = ""
                    }
                });
            }
    

    core tag标签不解析,无智能提示

    若_ViewImports.cshtml视图文件中无注入代码则添加注入代码。@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
    或者在视图中注入TagHelper:@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
    然后,asp-提示出来了,能解析了,也变颜色了~

    asp.net core 禁止视图编译到dll

    // 生成时会忽略视图的错误
    <MvcRazorCompileOnBuild>false</MvcRazorCompileOnBuild>
    // 发布时不编译视图到dll
    <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
    
  • 相关阅读:
    工单组件增强
    一些BAPI
    实例程序
    使用BAPI一定要提交和回滚(错误)
    动态内表值导出为TXT文件
    网页常用功能
    Code Complete
    Typescript 解构 、展开
    Typescript变量声明
    TypeScript基础数据类型
  • 原文地址:https://www.cnblogs.com/morang/p/7233278.html
Copyright © 2020-2023  润新知