0

this is my controller

public ActionResult Index()
    {
        return View();
    }
    [HttpPost]
    public ActionResult Validate(HttpPostedFileBase excelfile)
    {
        if(excelfile==null || excelfile.ContentLength==0)
        {
            TempData["Message"] = "Please select a excel file";
            return View("Index");

       }

From here i am passing a TempData["Message"] to view.how to check whether TempData["Message"] is not null in view ?

And in my view i am using <script> @TempData["Message"]</script> to give a alert

E. Zeytinci
  • 2,642
  • 1
  • 20
  • 37
sahana i.s
  • 21
  • 1
  • 5
  • check this..https://stackoverflow.com/questions/30057854/how-can-i-check-if-tempdata-is-null-through-integration-with-jquery – sp_m Jan 15 '20 at 05:43

2 Answers2

1

you can use:

@if (TempData["Message"] != null)
    {
      @TempData["Message"].ToString()
   }
Rupak
  • 409
  • 1
  • 3
  • 18
0

Try like this ,it will fix your issue

$(document).ready(function() {
var success = @((TempData["Message"] != null).ToString().ToLower());

if (success == true) {
        //Do your code here
  }
});
Ishwar Gagare
  • 723
  • 3
  • 9