在ViewData的未Ajax.BeginForm显示 [英] ViewData not shown in Ajax.BeginForm
问题描述
我已经creatd的局部视图和里面我使用AJAx.BeginForm。在帖子编辑操作方法,我加入可视数据筛选
I have creatd a partial view and inside it I am using AJAx.BeginForm. In Post Edit Action Method, I am adding VIEWDATA Like this
if (ModelState.IsValid)
{
service.SaveAccount(account);
TempData["message"] = "Account has been updated successfully!";
AccountInfo accountInfo = new AccountInfo();
accountInfo.AccountStatuses = service.GetAccountStatuses();
accountInfo.AccountTypes = service.GetAccountTypes();
accountInfo.CreditTerms = service.GetCreditTerms();
return View("DisputeSubscriber", accountInfo);
}
else
{
return PartialView("_UpdateAccountDetails", account);
}
和重定向到相同的部分观点。在局部视图,我加入这样的:
and redirecting to same partial view. In partial view, I have added like this:
@if (TempData["message"] != null)
{
<div class="Message">
I am here.
@TempData["message"]
</div>
}
但这个消息不是表演。此消息也在里面AJAX.BeginForm。请建议
but this message is not shows. this message is also inside AJAX.BeginForm. Please suggest
我是否需要重新定向,而不是局部视图主视图或有我丢失的东西。
Do I need to redirect main view instead of partial view or there is something I am missing
推荐答案
您似乎是使用TempData的,而不是ViewData的是的不太一样。你也提到,您使用的是 Ajax.BeginForm
来调用这个控制器动作。由于这是一个AJAX调用确保您已指定 UpdateTargetId
在AjaxOptions使得到的部分地方被注入到DOM:
You seem to be using TempData and not ViewData which is not quite the same. Also you mentioned that you are using an Ajax.BeginForm
to invoke this controller action. Since this is an AJAX call make sure that you have specified an UpdateTargetId
in your AjaxOptions so that the resulting partial is injected somewhere into the DOM:
@using (Html.BeginForm(new AjaxOptions { UpdateTargetId = "foo" }))
{
...
}
<div id="foo"></div>
这篇关于在ViewData的未Ajax.BeginForm显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!