我想在MVC的部分页面上显示错误/成功消息。但它正在主页上显示 [英] I want to show error/success message on partial page in MVC. But it is showing on main page

查看:89
本文介绍了我想在MVC的部分页面上显示错误/成功消息。但它正在主页上显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的问题是,我正在提交页面并从db获取错误/成功消息。我想在部分页面上显示错误/成功消息。但它显示在主页面上。





请帮助



我尝试过:



我的代码:



主视图ClientInviteLetter :

@using(Html.BeginForm(SaveCustomerLetter,Document,null,FormMethod.Post,new {id =customerLetter,enctype =multipart / form-data}))

{

@ Html.Partial(SaveCustomerDetailsPartialView)



}

b / b






部分查看SaveCustomerDetailsPartialView:



......

.........



Hi,

My issue is , I am submitting page and getting error/success msg from db .I want to show error/success message on partial page. but it is showing on main page.


Please help

What I have tried:

my code :

Main View ClientInviteLetter :
@using(Html.BeginForm("SaveCustomerLetter", "Document", null, FormMethod.Post, new { id = "customerLetter", enctype = "multipart/form-data" }))
{
@Html.Partial("SaveCustomerDetailsPartialView")

}




Partial View SaveCustomerDetailsPartialView:

......
.........



@ Html.TextBoxFor(model => model.ClientLetterDetails.DocumentUrl,new {id =clientLetterUpload,type =file,style =background-color:White})


@Html.TextBoxFor(model => model.ClientLetterDetails.DocumentUrl, new { id = "clientLetterUpload", type = "file", style = "background-color:White" })





.......

.......



Contro ller:



[HttpPost]

public ActionResult SaveCustomerLetter(iVisa.UI.Entities.Model.Client customerViewModel,FormCollection frmCustomerLetterViewModel)
{

....

...



返回RedirectToAction(ClientInviteLetter, WebConstants.Document);

}



.......
.......

Controller:

[HttpPost]
public ActionResult SaveCustomerLetter(iVisa.UI.Entities.Model.Client customerViewModel, FormCollection frmCustomerLetterViewModel)
{
....
...

return RedirectToAction(ClientInviteLetter ,WebConstants.Document);
}

推荐答案

//Controller- Action code :- 
this.SetNotification("your message form db", NotificationEnumeration.Success);
    
//define SetNotification method to store the error/success message
public void SetNotification(string message, NotificationEnumeration notifyType, bool autoHideNotification = true)
        {
            this.TempData["Notification"] = message;
            this.TempData["NotificationAutoHide"] = (autoHideNotification) ? "true" : "false";
            switch (notifyType)
            {
                case NotificationEnumeration.Success:
                    this.TempData["NotificationCSS"] = "<YourSuccessCssName>";
                    break;
                case NotificationEnumeration.Error:
                    this.TempData["NotificationCSS"] = "<YourErrorCssName>";
                    break;
                case NotificationEnumeration.Warning:
                    this.TempData["NotificationCSS"] = "<YourWarningCssName>";
                    break;
            }
        }

//View :-
//Inside your form, create an empty div to show the message
<div id="NotificationBox" class="@TempData["NotificationCSS"]" style="height: 10px;text-align:center;color:green">
</div>


这篇关于我想在MVC的部分页面上显示错误/成功消息。但它正在主页上显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆