小编Hei*_*del的帖子

字符串MinLength和MaxLength验证不起作用(asp.net mvc)

我有这门课

using System.ComponentModel.DataAnnotations;
using Argussoft.BI.DAL.Domain.Users;

namespace Argussoft.BI.DAL.DTOs.UserDTOs
{
    public class CreateUserDto
    {
        [Required(ErrorMessage = "??????? ?????")]
        [MaxLength(User.EmailLength, ErrorMessage = "???????????? ????? ?????? 40 ????????")]
        [RegularExpression(User.NameRegularExpression, ErrorMessage = "????? ????? ????????? ?????? ????????? ???????, ??????, ?????????????, ?????")]
        public string Name { get; set; }

        [Required(ErrorMessage = "??????? Email")]
        [MaxLength(User.EmailLength, ErrorMessage = "???????????? ????? ?????? ??????????? ????? 100 ????????")]
        [RegularExpression(User.EmailRegularExpression, ErrorMessage = "??????? ?????????? ????? ??????????? ?????")]
        public virtual string Email { get; set; }

        [Required(ErrorMessage = "??????? ??? ????????????")]
        [MaxLength(User.FullNameLength, ErrorMessage …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-mvc-3 asp.net-mvc-4

47
推荐指数
2
解决办法
12万
查看次数

asp.net mvc @ Html.CheckBoxFor

我的表格中有复选框
在此输入图像描述

我添加了我的模型

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;

 namespace CorePartners_Site2.Models
 {
public class CareerForm
     {
    //....
    public List<CheckBoxes> EmploymentType { get; set; } 
      }
 }

 public class CheckBoxes
 {
     public string Text { get; set; }
     public bool Checked { get; set; }
 }
Run Code Online (Sandbox Code Playgroud)

并在我的表格中添加

@Html.CheckBoxFor(model => model.EmploymentType, new { id = "employmentType_1" })
@Html.CheckBoxFor(model => model.EmploymentType, new { id = "employmentType_2" })
@Html.CheckBoxFor(model => model.EmploymentType, new { id = "employmentType_3" })
Run Code Online (Sandbox Code Playgroud)

但是我弄错了
在此输入图像描述

怎么了?

.net c# asp.net-mvc razor asp.net-mvc-4

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

Laravel 5.4以不同方式显示闪存错误和成功消息

来自我的PostController的方法

public function store(PostRequest $request)
    {
        if (Post::create($request->all())) {
            $request->session()->flash('status', 'Post was successfully added!');
        } else {
            $request->session()->flash('status', 'Error!');
        }
        return redirect('/');
    }
Run Code Online (Sandbox Code Playgroud)

索引视图

<?php if(session()->has('status')){
        echo '<div style="text-align: center">';
        echo session()->get('status');
        echo '</div>';
    }?>
Run Code Online (Sandbox Code Playgroud)

如何以不同的方式显示错误和成功消息?

laravel

13
推荐指数
2
解决办法
3万
查看次数

如何在@ Html.TextBox mvc4中同时添加css类和id

我需要在@ Html.TextBox mvc4中同时添加css类和id.我试试

@Html.TextBox("name", new { id = "name"}, new { @class = "text-field" })
Run Code Online (Sandbox Code Playgroud)

但结果我得到了

 <input class="text-field" id="name" name="name" type="text" value="{ id = name }">
Run Code Online (Sandbox Code Playgroud)

我这里不需要属性值.
我需要得到

 <input type="text" value="" name="name" id="name" class="text-field" />
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-4

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

如何创建MVC 4 @ Html.TextBox type ="file"?

我需要在表单中添加以下字段

<input type="file" class="input-file" />
Run Code Online (Sandbox Code Playgroud)

我创建模型并描述这个领域(最后一个领域)

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;

 namespace CorePartners_Site2.Models
 {
     public class FeedbackForm
     {
    public string Name { get; set; }
    public string Email { get; set; }
    public string Phone { get; set; }
    public string Company { get; set; }
    public string AdditionalInformation { get; set; }
    public HttpPostedFileBase ProjectInformation { get; set; }
     }
 }
Run Code Online (Sandbox Code Playgroud)

并创造

@Html.TextBox(null, null, new { type="file", @class="input-file" })
Run Code Online (Sandbox Code Playgroud)

但它不起作用,我得到一些例外.怎么了?

asp.net-mvc asp.net-mvc-4

10
推荐指数
2
解决办法
5万
查看次数

输入type ="number"with pattern ="[0-9]*"允许firefox中的字母

所以,所有问题都在主题标题中.输入type="number"pattern="[0-9]*"在Chrome精品工程,但允许在FF字母.有没有办法在不使用jQuery或JS的情况下修复它?

.small-input {
		-moz-appearance: textfield;
}
.small-input::-webkit-inner-spin-button {
			display: none;
		}

.small-input::-webkit-outer-spin-button,
.small-input::-webkit-inner-spin-button {
			-webkit-appearance: none;
			margin: 0;
		}
	}
Run Code Online (Sandbox Code Playgroud)
<input class="small-input " pattern="[0-9]*" value="" type="number">
Run Code Online (Sandbox Code Playgroud)

css html5

9
推荐指数
2
解决办法
9314
查看次数

是的:将字段本身与另一个字段进行比较

我有

StartIntensity: yup.number(),
EndIntensity: yup
    .number()
    .when(
        "StartIntensity",
        (StartIntensity: number, schema: any) => {
            return !!StartIntensity
                ? schema.moreThan(
                        StartIntensity,
                        "Max should be > min"
                  )
                : schema;
        }
    ),
Run Code Online (Sandbox Code Playgroud)

但我需要这样的东西

StartIntensity: yup.number(),
EndIntensity: yup
    .number()
    .when(
        "StartIntensity, EndIntensity",
        (StartIntensity: number, EndIntensity: number, schema: any) => {
            return !!StartIntensity && StartIntensity !== EndIntensity
                ? schema.moreThan(
                        StartIntensity,
                        "Max should be > min"
                  )
                : schema;
        }
    ),
Run Code Online (Sandbox Code Playgroud)

但上面的代码不能正常工作。是否有可能通过其他方式执行此验证?

javascript yup

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

momentjs 仅用于时间值

我使用 momentjs 来处理日期和时间

let dateAndTime = moment(component.props.data.value, moment.ISO_8601);
let date = '',
  time = '';
if (dateAndTime) {
  if (moment(dateAndTime, 'YYYY-MM-DD', true).isValid()) {
    date = moment(dateAndTime).format('YYYY-MM-DD');
  }

  if (moment(dateAndTime, 'HH:mm', true).isValid()) {
    time = moment(dateAndTime).format('HH:mm');
  }
}
Run Code Online (Sandbox Code Playgroud)

如果component.props.data.value包含日期和时间之类的2018-05-22 14:45或仅包含日期之类的,则此代码工作得很好2018-05-22。问题是有时component.props.data.value只包含像 一样的时间14:45,因此moment(component.props.data.value, moment.ISO_8601)不会创建矩对象并且下面的代码不会执行。有没有办法只处理时间?

javascript momentjs

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

asp.net mvc 4将表单从站点发送到电子邮件

我在我的mvc网站上有反馈表,看起来像

在此输入图像描述

我需要将表单发送到电子邮件.

我为我的表单创建了模型

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;

 namespace ComponentTrading.Web.Models
 {
public class FeedbackForm
    {
    public string Name { get; set; } 
    public string Email { get; set; } 
    public string Phone { get; set; }
    public string Message { get; set; }
    }
}
Run Code Online (Sandbox Code Playgroud)

我为我的表单Contacts.cshtml创建了视图

 @using (Html.BeginForm("Contacts", "Home", FormMethod.Post, new { id = "contact-form" }))
{
<fieldset>
    @Html.TextBoxFor(model => model.Name, new { @Value = Name })
    @Html.TextBoxFor(model => model.Email, new { @Value = "E-mail" })
    @Html.TextBoxFor(model …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-4

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

从$ _SESSION获取数据

我正在尝试创建简单的服务器端验证,这是我的方法

public function create() {
        $name = $_POST['name'];

        session_start();
        unset($_SESSION['errors']);

        $count = $this->model->checkIfUserExists($name);
        if($count > 0) {       
            $_SESSION['errors'] = array(
                'message'   => 'User Already Exists',
                'variables' => array(
                    'name'     => $_POST['name'],
                    'password' => $_POST['password'],
                ),
            );  

            header('location: ' . URL . 'user/registration');
            exit;
        }           

        $data = array();
        $data['name'] = $_POST['name'];
        $data['password'] = $_POST['password'];
        $this->model->create($data);            
        header('location: ' . URL);
    }
Run Code Online (Sandbox Code Playgroud)

以及来自registration.php的代码

<?php 

if (isset($_SESSION['errors']) && count($_SESSION['errors']) > 0) {

echo '<ul>';
foreach ($_SESSION['errors'] as $error) {
    echo '<li>' . …
Run Code Online (Sandbox Code Playgroud)

php session

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