C# 在mVC4中更改按钮文本而不刷新页面
我正在用MVC做我的应用程序。在我看来,我有一个名为EmailId的文本框和一个提交按钮。如果我输入电子邮件id并提交按钮,按钮的标签将更改为Verify,文本框应在不刷新页面的情况下清除 我的查看页面是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"
<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 />
<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 />
<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 我们必须做以下事情,使您的页面工作
$('#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");
}
});
});