使用mvc控制器向jjax functnality发送jquery字符串数据不起作用

时间:2017-01-03 05:49:31

标签: javascript ajax asp.net-mvc

  1. 我创建了一个signup.cshtml。这个页面是设计使用 JavaScript功能。我想做我的注册页面数据用户 输入存储在数据库中的名称,电子邮件,密码,电子邮件。

  2. 为此,我使用ajax功能将JQuery数据传递给 发布到controller.But在ajax功能它不工作。请帮助我这是我第一次尝试ajax功能 使用。

  3. 注册表数据

     namespace WealthApp.Model
     {
        using System;
        using System.Collections.Generic;
    public partial class Singup
    {
    public int UserId { get; set; }
    public string UserName { get; set; }
    public string Email { get; set; }
    public string MobileNo { get; set; }
    public string password { get; set; }
    }
    }
    
  4. 我的Singupjs代码

    function SaveSignUp() {
      var User = $("#User").val();
      var Email = $("#Email").val();
      var MobileNo = $('#MobileNo').val();
      var Password = $('#Password').val();
     localStorage.setItem("User", User);
     localStorage.setItem("Email", Email);
     localStorage.setItem("MobileNo", MobileNo);
      localStorage.setItem("Password", Password);
      var Users = localStorage.getItem("User");
      var Emails = localStorage.getItem("Email");
      var MobileNos = localStorage.getItem("MobileNo");
      var Passwords = localStorage.getItem("Password");
      var total = (MobileNos, Passwords, Emails, Users);
      LoadTable(User);
      document.querySelector('.cont_forms').className = "cont_forms    cont_forms_active_sign_up";
    document.querySelector('.cont_form_sign_up').style.display = "block";
    document.querySelector('.cont_form_login').style.opacity = "0";
    setTimeout(function () {
      document.querySelector('.cont_form_sign_up').style.opacity = "1";
     }, 100);
    
     setTimeout(function () {
     document.querySelector('.cont_form_login').style.display = "none";  }, 400);
    
    $(".cont_forms").removeClass("cont_forms_active_sign_up");
    $(".cont_form_sign_up").css("display", "none");
    $(".cont_form_login").css("display", "1");
    
    setTimeout(function () {
        $('.cont_form_sign_up').css("opacity", "0");
    }, 100);
    
    setTimeout(function () {
        $('.cont_form_login').css("display", "none");
    }, 400);
    
    
    //display the m=success message to the screen
    $(".SuccessMessage").text("Congratulation You have successfully Signedup..!!!");
    
    $(".SuccessMessage").css("display", "inline-block");
    
    setTimeout(function () {
        $(".SuccessMessage").css("display", "none");
    }, 3000);
    
    console.log($(".SuccessMessage").text());
     }
     function LoadTable(User) {
      $.ajax({
       url: '@Url.Action("SignUp","Default1")',
       data: { 'User': User },
       type: "POST",
       cache: false,
       success: function (data) {
        alert('enter');
        $("# SignUpDetails").html("");
        $("# SignUpDetails").html(data);
      }
     });
    
  5. 我的Default1Controller

      private WFTradeEntities db = new WFTradeEntities();
        public ActionResult Signup()
        {
          return View();
        }
    
    [HttpPost]
    public ActionResult SignUp(int User, Singup Signup)
    {
    
        if (ModelState.IsValid)
        {
            db.Singups.Add(Signup);
    
            db.SaveChanges();
    
            return RedirectToAction("_SignUpTable");
        }
        else
        {
            return View(Signup);
        }
    }
    

0 个答案:

没有答案