Asp.net mvc 提交后页脚中的电子邮件表单将消失
我是.NETMVC新手,出于学习目的,我在我的页脚中制作了一个简单的电子邮件通讯注册表单Asp.net mvc 提交后页脚中的电子邮件表单将消失,asp.net-mvc,Asp.net Mvc,我是.NETMVC新手,出于学习目的,我在我的页脚中制作了一个简单的电子邮件通讯注册表单 @using (Html.BeginForm("details", "Home", FormMethod.Post)) { <div class="form-group form-inline"> <label class="margin20">Sign up for newsletter</label> @Html.TextBox
@using (Html.BeginForm("details", "Home", FormMethod.Post))
{
<div class="form-group form-inline">
<label class="margin20">Sign up for newsletter</label>
@Html.TextBoxFor(Model => Model.Email, new { id = "input1", Class = "form-control", Style = "display:inline-block; max-width:200px", Placeholder = "Example@Example.com", type = "email" })
<button type="submit" disabled class="btn btn-default" style="display:inline-block" id="emailSignup">Signup</button>
</div>
}
@使用(Html.BeginForm(“details”,“Home”,FormMethod.Post))
{
注册时事通讯
@Html.TextBoxFor(Model=>Model.Email,新的{id=“input1”,Class=“form control”,Style=“display:inline block;最大宽度:200px”,占位符=”Example@Example.com,type=“email”})
报名
}
目前该表单运行良好(我可以输入电子邮件,提交后会收到确认邮件)
当用户提交电子邮件时,用户将被重定向到另一个页面。但是,我希望此表单在同一页面上工作,以便在按下提交按钮后,它会显示类似“感谢订阅”的内容,而不是移动到新视图
我想,解决这个问题的简单方法是制作一个jQuery脚本,隐藏电子邮件表单,并取消隐藏一个div,上面写着“感谢您注册”
然而,我想用MVC的方式来做这件事,那么“最”正确的做法是什么呢
@RenderSection
可能是一个选项,我想?通常,根据模型状态(即电子邮件是否已发送)使用简单的标志完成。例如(非常粗糙的代码)
@if(emailHasBeenSent)
{
谢谢注册!
}
其他的
{
你的注册码
}
我对MVC也相当陌生,但这是我从其他人的工作代码中看到的 那是天才。多谢各位@JeppeChristensen如果答案对你有效,请确保你接受它!我相信经验丰富的人可以提出更好的方法,但谢谢!
@if (emailHasBeenSent)
{
<div class="polite-message"> Thanks for signing up! </div>
}
else
{
<div class="form-group form-inline"> your sign up code </div>
}