Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.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
C# 在mVC4中更改按钮文本而不刷新页面_C#_Asp.net Mvc_Asp.net Mvc 4_Razor_Ajaxform - Fatal编程技术网

C# 在mVC4中更改按钮文本而不刷新页面

C# 在mVC4中更改按钮文本而不刷新页面,c#,asp.net-mvc,asp.net-mvc-4,razor,ajaxform,C#,Asp.net Mvc,Asp.net Mvc 4,Razor,Ajaxform,我正在用MVC做我的应用程序。在我看来,我有一个名为EmailId的文本框和一个提交按钮。如果我输入电子邮件id并提交按钮,按钮的标签将更改为Verify,文本框应在不刷新页面的情况下清除 我的查看页面是 <div class="sign" id="email"> @using (Html.BeginForm("Randa", "BU", FormMethod.Post)) { <div class="sign1"

我正在用MVC做我的应用程序。在我看来,我有一个名为EmailId的文本框和一个提交按钮。如果我输入电子邮件id并提交按钮,按钮的标签将更改为Verify,文本框应在不刷新页面的情况下清除

我的查看页面是

    <div class="sign" id="email">
        @using (Html.BeginForm("Randa", "BU", FormMethod.Post))
        {
            <div class="sign1">

                <div class="sign2" style="height:267px;width:562px;margin-left:214px" id="cdiv">
                                     @Html.TextBox("EmailId","", new {@placeholder ="Enter the Email id",id="txtemail "})<br /><br />

                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Sign Up" id="btn" onclick="addbutton()" class="addbutton"/>


                </div>
            </div>

        }
    </div>
    <div class="drnd" id="rnd" style="display:none">
        @using (Html.BeginForm("Ra_verify", "BU", FormMethod.Post))
        {
            <div class="sign1">

                <div class="sign2" style="height:267px;width:562px;margin-left:214px" id="cdiv">
                    @Html.TextBox("Getran", "", new { @placeholder = "Enter the Randam", id = "txtrnd" })<br /><br />

                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Verify" id="btnrnd" class="addbutton" />


                </div>
            </div>

        }
    </div>
    }
<script type="text/javascript">
        var btxt = "Verified";
        document.getElementById("#btn").innerHTML = btxt;
    </script>
    <script type="text/javascript">
        function addbutton()
        {

             ($("#email").hide())

                $("#rnd").show();


        }
    </script>
有人能帮我吗?
提前感谢。

首先,您需要使用
Ajax.BeginForm

success
功能中,您可以为明文EmailId编写以下代码,并单击一个提交按钮

$("#EmailId").val("");
$("#btn").val("Verify");

如果要执行上述操作,您不需要两个表单。

只要我们想在不刷新的情况下更新网页中的值,就必须使用Ajax

我们必须做以下事情,使您的页面工作

  • 从视图中删除BeginForm块,因为当我们使用BeginForm时,它将向控制器发送请求并刷新页面
  • 使用Ajax将信息传递给控制器并更新页面,而不刷新页面
  • 由于您在控制器中有两个POST操作,所以请保留div“rnd”和“email”

    下面是一个带有Ajax选项的示例脚本块,用于根据您的请求更新页面

      $('#btn').click(function () {
    
      var urlinfo = '/Home/Randa';
      var textboxValue = $('#txtemail').val();
    
      $.ajax({
        type: "POST",
        data: { value: textboxValue },
        url: urlinfo,
        success: function (result) {          
          $('#email').hide();
          $('#rnd').show();
        },
        error: function () {
          alert("failed");
        }
      });
    });
    

    然后您需要使用ajax提交值。单击一个按钮,我需要发送电子邮件,同时我需要显示第二个(“rnd”)div,并从第二个div文本框中获取值。是否可能。发送电子邮件是在服务器端完成的,因此当
    表单提交到
    操作时
    Randa
    。添加您的代码以发送邮件。在成功事件中使用此代码
    $(“#rnd”).show()
    $(“#Getran”).val()
    
      $('#btn').click(function () {
    
      var urlinfo = '/Home/Randa';
      var textboxValue = $('#txtemail').val();
    
      $.ajax({
        type: "POST",
        data: { value: textboxValue },
        url: urlinfo,
        success: function (result) {          
          $('#email').hide();
          $('#rnd').show();
        },
        error: function () {
          alert("failed");
        }
      });
    });