Denmark Puso

Denmark Puso

  • 1.8k
  • 73
  • 853

ViewBag.Message not working?

Aug 10 2019 2:04 AM
im using asp.net mvc my viewbag message not  working can someone help me. 
 
else
{
var order = new Order
{
ClientId = model.ClientId,
StateId = model.StateId,
CityId = model.CityId,
TownId = model.TownId,
Postcode = model.Postcode,
Address = model.Address,
DatePosted = DateTime.Now,
DeliveryDate = Convert.ToDateTime(model.DeliveryDate),
Quantity = model.Quantity,
Status = "Lined-up",
DateDelivered = null,
Notes = model.Notes ?? ""
};
_orderService.Add(order);
ViewBag.Message = "Your order successfully inserted";
return RedirectToAction("add");
}
 
 My script
@if (ViewBag.Message != null)
{
<script type="text/javascript">
window.onload = function () {
alert("@ViewBag.Message");
};
</script>
}
 
 
 

Answers (12)