使用查看包显示消息而无需刷新视图 [英] Display message using view bag without refreshing view
本文介绍了使用查看包显示消息而无需刷新视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个来自ControllerA的视图A,该视图具有两个按钮1.创建2.更新
I have a view A From ControllerA Which has two buttons 1. Create 2. Update
单击更新或创建其时,将打开一个新的局部视图B作为另一个控制器B的弹出窗口.
Upon clicking update or Create its opening a new partial viewB As popup from another controller B.
iam试图获取的是如果在b中成功创建了一条记录,那么我现在将关闭弹出窗口.除了关闭弹出窗口外,我还想在视图A中显示一条消息.
What iam trying to get is If a record is created successfully in b I am now closing the popup. Apart from closing the popup I want to display a message in view A.
我正在尝试这样:控制器B
I am trying like this: Controller B
public ActionResult Create(FormCollection args)
{
var obj = new ProjectManagernew();
var res = new ProjectViewModelNew();
try
{
UpdateModel(res);
if (obj.AddUpdateOrderField(res))
{
ViewBag.RecordAdded = true;
ViewBag.Message = "Project Added Successfully";
}
return View(res);
}
catch (Exception)
{
//ModelState.AddRuleViolations(res.GetRuleViolations());
return View(res);
}
}
在视图A中:
@if(ViewBag.Message!=null)
{
@ViewBag.Message
}
视图B:
@model DreamTrade.Web.BL.ViewModels.ProjectViewModelNew
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout_Popup.cshtml";
}
@if (ViewBag.RecordAdded != null && (bool)ViewBag.RecordAdded)
{
<script type="text/javascript">
parent.$.nmTop().close();
$('#jqgprojectnew').text("Record added successfully");//jqgprojectnew is the name of grid in view A
</script>
}
<h2>Create</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Project</legend>
@Html.HiddenFor(model => model.ProjectID)
<div class="editor-label">
@Html.LabelFor(model => model.ProjectDetail)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ProjectDetail)
@Html.ValidationMessageFor(model => model.ProjectDetail)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ProjectRef)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ProjectRef)
@Html.ValidationMessageFor(model => model.ProjectRef)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ProjectName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ProjectName)
@Html.ValidationMessageFor(model => model.ProjectName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.StatusList)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.ProjectStatusId,new SelectList(Model.StatusList,"SourceStatusId","Description"),"Please Select")
@Html.ValidationMessageFor(model => model.ProjectStatusId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.CustomerList)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.Id,new SelectList(Model.CustomerList,"Id","Name"),"Please Select")
@Html.ValidationMessageFor(model => model.Id)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<div>
<a href="javascript:parent.$.nmTop().close()">Back to list</a>
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
请让我知道我在哪里做错了
please let me know where iam doing wrong
推荐答案
在要显示消息的地方添加标签字段.
Include a label field where you want to show the message.
<label id=mylabel></label>// Add this before jqgrid
将代码修改为:
@if (ViewBag.RecordAdded != null && (bool)ViewBag.RecordAdded)
{
<script type="text/javascript">
parent.$.nmTop().close();
$('#mylabel').text("Record added successfully");
</script>
}
这篇关于使用查看包显示消息而无需刷新视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文