Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 提交表格不';行不通_Javascript_Jquery_Html_Asp.net Mvc 5 - Fatal编程技术网

Javascript 提交表格不';行不通

Javascript 提交表格不';行不通,javascript,jquery,html,asp.net-mvc-5,Javascript,Jquery,Html,Asp.net Mvc 5,我试过一些帖子中的建议,但都不管用 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; namespace HW_MVC_STORE.Models { public class Product { [Key] [RegularExpressi

我试过一些帖子中的建议,但都不管用

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

namespace HW_MVC_STORE.Models
{
    public class Product
    {
        [Key]
        [RegularExpression("^[a-zA-Z0-9]+$", ErrorMessage = "Only upper- and lower- case letters and numbers.")]
        [Required]
        [StringLength(5,MinimumLength=5, ErrorMessage = "Please enter 5 characters serial.")]
        public string SerialNo { get; set; }


        [RegularExpression("^[a-zA-Z]+$", ErrorMessage = "Only upper- and lower- case letters")]
        [Required]
        [StringLength(10, MinimumLength=2, ErrorMessage="Please enter between 2 and 10 characters.")]
        public string Name { get; set; }

        [RegularExpression("^[0-9]+$", ErrorMessage = "Integers only")]
        [Required]
        public string Quatity { get; set; }

        [RegularExpression("^([0-9]+[.][0-9]+)|([1-9]+[0-9]*)$", ErrorMessage = "Numbers only, bigger then zero")]
        [Required]
        public string Price { get; set; }
    }
}

我不明白为什么它甚至调用SendData()函数,在所有文本框正确归档之前,它不会离开表单

我如何修复它,或者至少修复它有什么问题

您需要:

<form id="formAdd" onsubmit="return SendData(); return false;">
<form id="formAdd" onsubmit="return SendData();">
<form id="formAdd" onsubmit="SendData()">

  • 函数
    SendData
    不返回值,因此
    returnsenddata()没有意义
  • 不返回false将导致重新加载页面(默认操作)
如果
SendData
中的ajax帖子不起作用,我们需要更多详细信息。

您需要:

<form id="formAdd" onsubmit="return SendData(); return false;">
<form id="formAdd" onsubmit="return SendData();">
<form id="formAdd" onsubmit="SendData()">

  • 函数
    SendData
    不返回值,因此
    returnsenddata()没有意义
  • 不返回false将导致重新加载页面(默认操作)

如果
SendData
中的ajax帖子不起作用,我们需要更多详细信息。

在ASP.NET MVC中,您可以执行
@Html.BeginForm
。您可能想从您的模型生成一个视图。我可以在这里给出表单id吗?我在这里看不到任何适合我的需要的东西。(id到表单并调用JS函数)。你是否尝试从模型或控制器创建视图?我对这一点不熟悉,所以我使用教程和文档,所以我不太确定“从模型或控制器创建视图”是什么意思。我有一个模型,正如你在文章中看到的,和它的强类型视图,当然还有一个控制器。但是submit调用SendData()的小(大)东西不要紧,其他一切都很好。在ASP.NET MVC中,您可以执行
@Html.BeginForm
。您可能想从您的模型生成一个视图。我可以在这里给出表单id吗?我在这里看不到任何适合我的需要的东西。(id到表单并调用JS函数)。你是否尝试从模型或控制器创建视图?我对这一点不熟悉,所以我使用教程和文档,所以我不太确定“从模型或控制器创建视图”是什么意思。我有一个模型,正如你在文章中看到的,和它的强类型视图,当然还有一个控制器。但是submit调用SendData()的那个小(大)东西不要紧,其他一切都很好。也试过那个。每件事都很好,输入错误值时的注释,控制器中的验证(ModelState.IsValid)。唯一的问题是,当您单击“提交”按钮时,无论文本框中的值如何,它都会调用SendData()函数。您也尝试过这个方法。每件事都很好,输入错误值时的注释,控制器中的验证(ModelState.IsValid)。唯一的问题是,当您单击submit按钮时,无论文本框中的值如何,它都会调用SendData()函数。
<form id="formAdd" onsubmit="SendData(); return false;">