Abdul Ahmad
Abdul Ahmad

Reputation: 10021

display message in view after action method call

I have a view where a user can download a report. There are filters to choose from before downloading a report. When a person chooses filters and tries to download the report, if the report has no data, I want the action method to cause a client side message like :

"no data in report"

right now, what I'm attempting is to stop the method call, and call return redirectToAction('noDataActionMethod'), which is a partial view.

but other than that I'm not sure where to go from here. The ideal situation would be to be able to call some javascript when the partial view loads, but doing research shows that its not possible?

also, I don't want to open up a whole new view. I just want a partial view that I can fadeIn for 5 seconds and then fade out.

Upvotes: 0

Views: 191

Answers (1)

workabyte
workabyte

Reputation: 3755

You could put the message in the ViewBag and then display it that way on the client side. You dont need a partial view for this, just check server side if the bag has your message and then if so call the JS function to show a div that has you message in it.

the answer here may help, you would just use something like

ViewBag.NoDataMessage = "some message"; //in the controller 

then take the approach in the answer i linked to.

Something like this

@if (!string.IsNullOrWhiteSpace(ViewBag.NoDataMessage))
{
<script type="text/javascript">
    $('#MessageDiv').attr("innerHtml",'@ViewBag.NoDataMessage');
    //show your div
    //start timer to hide the div
</script>
}

Upvotes: 1

Related Questions