小编Jav*_*fca的帖子

使用ASP.NET MVC数据类型属性验证电子邮件地址

我在验证电子邮件方面遇到了一些问题.

在我的模型中:

[Required(ErrorMessage = "Field can't be empty")]
[DataType(DataType.EmailAddress, ErrorMessage = "E-mail is not valid")]
public string ReceiverMail { get; set; }
Run Code Online (Sandbox Code Playgroud)

在我看来:

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@Html.TextBoxFor(m => m.ReceiverMail, new { @placeholder="E-mail"}) <br />
@Html.ValidationMessageFor(m => m.ReceiverMail)
Run Code Online (Sandbox Code Playgroud)

现在,当你将场留空时,它正确地向我显示"场不能为空".但是当你填写一个无效的电子邮件地址,如:"fwenrjfw",那么表格并没有说"电子邮件无效".

如何获取表单以将输入验证为电子邮件地址?我正在寻找一些帮助.

c# validation asp.net-mvc email-validation

157
推荐指数
7
解决办法
24万
查看次数

从github中排除文件夹

我需要从我的Github中排除文件夹App_Data,但我不知道如何.

我有一个应用程序,它在目录中保存许多文件,如jpg文件:Source\MyProject\App_data\stored\filename.jpg

现在我需要从.gitignore文件中排除它

我不知道怎么做,所以我正在寻找一个例子

github

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

使用 Server.MapPath 保存文件

目前,我将文件保存到代码中硬编码的目录中:

var filePath = Path.Combine(@"C:\users\my documents\github\project\source\project\App_Data\stored\", package.Id + ".zip");
Run Code Online (Sandbox Code Playgroud)

但我需要使用 Server.MapPath .... 保存我的文件,例如:

FileInfo userFile = new FileInfo(Path.Combine(Server.MapPath("~/App_Data/stored"), package.Id));
Run Code Online (Sandbox Code Playgroud)

完整功能:

 public void CompressAndDeleteSources(FlinkeMailPackage package)
 {
    var filePath = Path.Combine(@"C:\users\my documents\github\project\source\project\App_Data\stored\", package.Id + ".zip");

    using (ZipFile zipFile = new ZipFile(filePath))
    {
      foreach (var file in package.FlinkeMailFileList)
      {               
        string bestandsNaam = @"C:\users\my documents\github\project\source\project\App_Data\uploads\" + file.OriginalName;
        zipFile.AddFile(bestandsNaam);
      }
       zipFile.Save();
    }

    foreach (var file in package.FlinkeMailFileList)
     {
         var filePathToDelete = @"C:\users\my documents\github\project\source\project\App_Data\uploads\" + file.FileName;
         File.Delete(filePathToDelete);
     }       
   }
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用Server.MapPath("~/App_Data/stored")它时,它不知道服务器是什么

编辑

我可以像这样使用它: HttpContext.Current.Server.MapPath("~/App_Data/stored"); 但我不能 …

asp.net file-upload

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

如何使用setInterval

在我的网站上我想要有两个背景图像,用setInterval改变,但我不知道如何让这个工作/

CSS:

body {
        padding-top: 20px;
        padding-bottom: 40px;
        background-image: url(/Assets/img/image1.jpg), url(/Assets/img/image2.jpg);
        background-repeat: repeat-x, repeat;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
    }
Run Code Online (Sandbox Code Playgroud)

.js文件:

$(document).ready(function () {

    (function () {
        var curImgId = 0;
        var numberOfImages = 2; // Change this to the number of background images
        window.setInterval(function () {
            $('body').css('background-image', 'url(/background' + curImgId + '.jpg)');
            curImgId = (curImgId + 1) % numberOfImages;
        }, 15 * 1000);
    })();
});
Run Code Online (Sandbox Code Playgroud)

我需要一些帮助来使用setInterval在image1.jpg和image2.jpg之间切换

编辑

我已将我的js更改为:

  $(document).ready(function () {
        setInterval(function () {
            $('body').toggleClass("/Assets/Style/background/Images1.css", "/Assets/Style/background/Images2.css"); …
Run Code Online (Sandbox Code Playgroud)

html javascript css

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