代码之家  ›  专栏  ›  技术社区  ›  Raman Sinclair

《View,Cloudinary API指南》中的C#代码

  •  1
  • Raman Sinclair  · 技术社区  · 8 年前

    我正在尝试制作asp。net mvc 5应用程序 ASP.NET image upload 指导

    我对指南的这一部分很好奇( on the photo here ): 正如我在那部分所理解的那样,我应该在View(cshtml)页面中编写代码。(因为之前在“<”中附加了js和运行脚本脚本“>”标签)

    如何在视图中编写这样的C#代码?我哪里错了?

    string cors_location = (new UriBuilder(Request.Url.AbsoluteUri) { Path = Url.Content("~/Content/cloudinary_cors.html") }).ToString();
    
    2 回复  |  直到 8 年前
        1
  •  1
  •   Rob    8 年前

    视图中的C#代码通常属于这样的服务器端块。。。

    @{
    
    string cors_location = (new UriBuilder(Request.Url.AbsoluteUri)
        { Path = Url.Content("~/Content/cloudinary_cors.html") }).ToString();
    
    
     }
    
        2
  •  1
  •   joint_ops    8 年前

    如何在视图中编写这样的C#代码?我哪里错了?

    你好 像这样添加“@”符号

    @{string cors_location = (new UriBuilder(Request.Url.AbsoluteUri) { Path = Url.Content("~/Content/cloudinary_cors.html") }).ToString();}
    

    也请检查 http://www.asp.net/web-pages/overview/getting-started/introducing-razor-syntax-c

    我的服务器应该会得到上传文件的链接

    要管理它,您应该这样做:

    在您的模型类中为例如创建属性。

    public string ImgUrl {get;set;}
    

    在您的视图控制器中,您应该从视图传递url值

    Img.Url = "My Image Url passed from View";
    

    然后将模型保存到数据库。

    更多信息,请查看 http://www.mikesdotnetting.com/article/259/asp-net-mvc-5-with-ef-6-working-with-files