jatin jatin

jatin jatin

  • NA
  • 6
  • 3.3k

Section not defined In Index.cshtml in asp.net mvc?

Dec 27 2019 6:32 AM
In MVC get an error:
 
Section not defined: "alertmethod"
 
I already define that method in Index.cshtml 
 
_Layout.cshtml
 
@RenderSection("alertmethod")   // I define this method in index.cshtml that's yI m using rendersection?? 
  1. <div class="container body-content">
    @RenderBody()
    @RenderSection("alertmethod")
    <footer>
    </footer>
    </div>

  2.   
  3.           
  4.   
HomeController
 
  1.         public ActionResult create()  
  2.         {  
  3.             return View();  
  4.         }  
  5.   
  6.         [HttpPost]  
  7.         public ActionResult create(studentmvcmodel stud)  
  8.         { 
  9.             ViewBag.message = "data inserted successfully";  
  10.             return RedirectToAction("Index");   
  11.         }  

 
 
Index.cshtml
  1. @{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
    }
     
    @section alertmethod
    {
    <script src="https://cdnjs.cloudflare.com/ajax/libs/AlertifyJS/1.13.1/alertify.min.js" type="text/javascript">
    $(function () {
    var successmessage = '@ViewBag.message'
    if (successmessage != '') //means aani '' length=0 ni alava hovu joiye
    {
    alertify.success(successmessage);
    }
    });
    </script>
    }
 How to resolve this issue??

Answers (4)