4

I'm using a FlashHelper to show flash message to users and I need to show partial view istead of default flash message. How can I do that or is that possible or not?.

I need a helper like that:

Flash.Success("_FlashMessagePartial",model)

Or Is there any library you suggest ?

Erkan Demirel
  • 4,302
  • 1
  • 25
  • 43
  • What is a flash-message? – TGlatzer Mar 02 '16 at 09:25
  • @TGlatzer I think it is an standard notification message, which will disappear itself after few seconds. Therefore `flash`. Advantage is that you don`t need to hide the message manually before another ajax operation. – Muflix May 23 '17 at 13:46

1 Answers1

0

You can't use it like this. If I have understand correct you want to show something like notifications to the users and you don't want your page to be refreshed. The correct answer is that you can do it but it is not correct. Your code will look as a mess you will have a hidden field for the notification and so on. It depends of what you what you want to accomplish. For example: I am using in my layout a global notification and my snipped looks like this

On the top of the layout just before the I place an if statement that checks whether error message exists in the TempData

@if(TempData["error"])
{
   // here you can visualize it well styled by some template for example
   <div class="notification-error">@TempData[error]</div>
}
@if(TempData["success"])
{
   // here you can visualize it well styled by some template for example
   <div class="notification-error">@TempData[error]</div>
}

Then in your controller if you have something to say to the user you can
just do what you are doing like:

public ActionResult SomeAction(MyModel model)
{
    if(something is not valid)
    {
       this.TempData["error"] user error
       return this.View(model);
    }
}



That case was if you need some server validation and proper message to the     
user. After that option you have to set a script on your layout that removes
the error and success notifications if they exist on the page loads. 

The other option if you need some modelstate validation on the client side you can take a look for js-unobtrusive validation that is driven by the viewmodel's attributes and it makes you automatic check on client side before it goes to the server.

The third option is if you need some other notification you can use a JS library called toastr. Examples library url It is light and very easy to use

Hope that this answer is explaining exactly what you need.

A.Sideris
  • 530
  • 3
  • 18