我正在使用MVC开发我的应用程序。我正在使用单个文本和按钮。点击按钮后,我需要发送电子邮件并显示部分视图。
控制器代码
public ActionResult BusinessUserRegister()
{
return View();
}
[HttpPost]
public ActionResult BusinessUserRegister(string Emailid)
{
string userId = System.Configuration.ConfigurationManager.AppSettings["UserTypeId"];
int typeid = Convert.ToInt32(userId);
EmailManager.SendConfirmationEmail(Emailid);
tbl_BusinessUser user = new tbl_BusinessUser();
user.RandomNumber = (int)Session["rd"];
user.EmailId = Emailid;
db.tbl_BusinessUser.Add(user);
db.SaveChanges();
//return View();
return PartialView("BusinessUserVerifyPartial");
}
查看
@model SYTMain.Models.tbl_BusinessUser
@{
ViewBag.Title = "BusinessUserRegister";
}
<h2>BusinessUserRegister</h2>
@using (Html.BeginForm())
{
<div class="sign2" style="height:267px;width:562px;margin-left:214px" id="emaildiv">
@*@Html.TextBox("EmailId", "", new { @placeholder = "Enter the Email ", id = "txtemail" })<br /><br />*@
<input type="text" name="Emailid" id="Email"/>
<input type="button" name="submit" value="Sign Up" id="Emailbtn" class="addbutton" />
</div>
<div id=" Emailverify" >
</div>
}
@section Scripts{
<script type="text/javascript">
$("#Emailbtn").click(function () {
debugger;
var url = '@Url.Action("BusinessUserRegister", "BU")';
$.post(url, { Emailid: $('#Email').val() }, function (data) {
// alert(data);
$("#Emailverify").html(data);
});
})
</script>
}
部分视图
<div id="EmailVerify">
<div class="sign3" style="height:267px;width:562px;margin-left:214px" id="verfieddiv">
@Html.TextBox("verify", "", new { @placeholder = "Enter the Random Number", id = "txtverified" })<br /><br />
<input type="submit" name="Verify" value="Verify" id="vbtn" />
</div>
</div>
我的问题是点击按钮时没有显示部分视图。
点击电子邮件发送给相应用户的按钮,同一页面正在显示,部分视图未加载。
答案 0 :(得分:0)
开始在“Emailverify”之前删除空格
<div id=" Emailverify" >
如果你使用JQuery代码从服务器发送和接收数据,你为什么使用Html.BeginForm()?可能你想使用type =“submit”而不是name =“submit”。单击确认按钮将表单发送到BusinessUserRegister操作,结果刷新所有页面,然后从头开始。我的建议是删除Html.BeginForm()和空格。