我的要求是在同一页面中显示结果而不重定向到另一个页面。我正在使用 Ajax.BeginForm() 执行此操作。但它重定向到另一个页面。有人可以帮忙吗?
我的.js文件:
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
我的查看代码:
@using (Ajax.BeginForm("UserAccountInfo", "Account", new AjaxOptions {UpdateTargetId = "result" }))
{
@Html.ValidationSummary(true)
<div id="result"></div>
<div class="t-12-user">First Name </div>
<div> @Html.TextBoxFor(model => model.FirstName, new { @class = "user-input-bx", MaxLength = "50"})</div>
<div class="t-12-user"> Email Address </div>
<div> @Html.TextBoxFor(model => model.EmailId, new { @class = "user-input-bx", MaxLength = "50" })</div>
<div><input type="submit" value="Save" /> </div>
}
控制器:
[HttpPost]
public ActionResult UserAccountInfo(RegisterModel Model)
{
// code
return Content("Thank you for subscribe", "text/html");
}
网络配置:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
任何人都可以帮助这一点,成功消息应该显示在同一页面中..