Checking to see if ViewBag has a property or not, to conditionally inject JavaScript

后端 未结 5 1113
轮回少年
轮回少年 2020-12-09 02:04

Consider this simple controller:

Porduct product = new Product(){
  // Creating a product object;
};
try
{
   productManager.SaveProduct(product);
   return          


        
5条回答
  •  心在旅途
    2020-12-09 02:12

    You can use ViewData.ContainsKey("yourkey").

    In controller:

    ViewBag.IsExist = true;
    

    In view:

    if(ViewData.ContainsKey("IsExist")) {...}
    

提交回复
热议问题