2

我的要求是在同一页面中显示结果而不重定向到另一个页面。我正在使用 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" />

任何人都可以帮助这一点,成功消息应该显示在同一页面中..

4

2 回答 2

1

返回为json。我认为它会为你工作。

于 2013-05-14T14:08:37.387 回答
0

你可以通过这两种方式...

解决方案 1:您必须在 /Views/Account 文件夹中使用您的内容创建一个局部视图并将其返回。

控制器:

[HttpPost]
public ActionResult UserAccountInfo(RegisterModel Model)
{
// code
return PartialView("_yourPartialView", model);
}

解决方案2:只需返回相同的视图并使用 ViewBag 变量将任何字符串发送到这样的视图......

控制器:

[HttpPost]
public ActionResult UserAccountInfo(RegisterModel Model)
{
// code
ViewBag.VariableName = "Thank you for subscribe";
return View();
}

看法:

@ViewBag.VariableName
于 2013-10-03T19:33:37.003 回答