Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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" })


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

Controller:

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

return RedirectToAction(ClientInviteLetter ,WebConstants.Document);
}
Posted
Updated 15-Feb-17 19:18pm

1 solution

C#
//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>
 
Share this answer
 
Comments
Singh Deepika 16-Feb-17 1:18am    
//In the script tag of your view

@if (TempData["Notification"] != null)
{

$("#NotificationBox").html('@TempData["Notification"]');
$("#NotificationBox").fadeIn(1000);
$("#NotificationBox").delay(5000).queue(function (next) {
$("#NotificationBox").html("");
$("#NotificationBox").css("background-color", "");
next();
});

}
manika123 17-Feb-17 0:33am    
Thanks Deepika for your reply. but my issue is bit different. I want to show my message on partial view not on main view.as of now it is showing on main view.
-Manika

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900